Created
April 7, 2012 10:17
-
-
Save Fivell/2327193 to your computer and use it in GitHub Desktop.
EmailValidator < ActiveModel::EachValidator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EmailValidator < ActiveModel::EachValidator | |
EmailAddress = /\A[\w!\#$%&'*+\/=?^_\`{|}~-]+(?:\.[\w!\#$%&'*+\/=?^_\`{|}~-]+)*@(?:\w(?:[\w-]*\w)?\.)+\w(?:[\w-]*[\w])?\z/ | |
def validate_each(record, attribute, value) | |
unless value =~ EmailAddress | |
record.errors[attribute] << (options[:message] || "is not valid") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment