Commit 8dae35ef21de0659e22db9e6217d674a6d60b66d
1 parent
a5712091
Exists in
master
and in
5 other branches
correcoes_aderencia: Add regex to validate full name on person model
Signed-off-by: David Carlos <ddavidcarlos1392@gmail.com> Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
Showing
1 changed file
with
15 additions
and
0 deletions
Show diff stats
lib/ext/person.rb
| ... | ... | @@ -6,6 +6,8 @@ class Person |
| 6 | 6 | |
| 7 | 7 | attr_accessible :percentage_incomplete |
| 8 | 8 | |
| 9 | + validate :validate_full_name | |
| 10 | + | |
| 9 | 11 | scope :search, lambda { |name="", state="", city="", email=""| |
| 10 | 12 | like_sql = "" |
| 11 | 13 | values = [] |
| ... | ... | @@ -55,6 +57,19 @@ class Person |
| 55 | 57 | self.user.secondary_email = value unless self.user.nil? |
| 56 | 58 | end |
| 57 | 59 | |
| 60 | + def validate_full_name | |
| 61 | + reg_firsts_char = /(^|\s)([a-z]|[0-9])/ | |
| 62 | + reg_special_char = /[^\w\*\s]/ | |
| 63 | + | |
| 64 | + invalid = reg_firsts_char.match(self.name) || reg_special_char.match(self.name) | |
| 65 | + | |
| 66 | + if invalid | |
| 67 | + self.errors.add(:name, _("Should begin with a capital letter and no special characters")) | |
| 68 | + return false | |
| 69 | + end | |
| 70 | + true | |
| 71 | + end | |
| 72 | + | |
| 58 | 73 | def software? |
| 59 | 74 | false |
| 60 | 75 | end | ... | ... |