Created
July 30, 2015 22:58
-
-
Save niaeashes/81359397e496cd63dbf3 to your computer and use it in GitHub Desktop.
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 | |
# Email address regex is copied from http://emailregex.com on "Ruby (simpler version)" | |
def validate_each(record, attr_name, value) | |
if ! ( value.blank? && options[:allow_blank] ) | |
record.errors.add(attr_name, :invalid_email, options) unless value =~ /\A([\w+\-][\w+\-.]*[\w+\-]|[\w+\-.])@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment