Guest User

Untitled

a guest
May 21st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. Valid:
  2. Something, Foobar 111.
  3.  
  4. Invalid:
  5. .......
  6.  
  7. validate :yourvalue_must_contain_at_least_3_alphabetic_characters
  8.  
  9. protected
  10.  
  11. def yourvalue_must_contain_at_least_3_alphabetic_characters
  12. unless yourvalue.gsub(/[^A-Z]/i,"").size > 2
  13. errors.add(:yourvalue, 'should have at least 3 alphabetic characters')
  14. end
  15. end
  16.  
  17. validates_format_of :password, :with => /([^a-zA-Z]*([a-zA-Z]+)[^a-zA-Z]*){3,}/
  18.  
  19. protected
  20.  
  21. def validate
  22. unless your_field.gsub(/[^A-Z]/i,"").size > 2
  23. errors.add("your_field", "Must contain at least 3 alphabetical characters")
  24. end
  25. end
Add Comment
Please, Sign In to add comment