Initial commit
This commit is contained in:
9
app/validators/email_validator.rb
Normal file
9
app/validators/email_validator.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
class EmailValidator < ActiveModel::EachValidator
|
||||
EMAIL_REGEX = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
|
||||
|
||||
def validate_each(record, attribute, value)
|
||||
unless value =~ EMAIL_REGEX
|
||||
record.errors[attribute] << (options[:message] || "is not an email")
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user