2016-02-08 18:16:18 +01:00
|
|
|
class EmailFormatValidator < ActiveModel::Validator
|
|
|
|
def email_regex
|
|
|
|
/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
|
|
|
|
end
|
|
|
|
|
|
|
|
def validate(record)
|
|
|
|
return if record.email.blank?
|
2018-01-11 19:04:39 +01:00
|
|
|
record.errors[:base] << "Email invalide" if !email_regex.match(record.email)
|
2016-02-08 18:16:18 +01:00
|
|
|
end
|
|
|
|
end
|