debian-mirror-gitlab/app/validators/email_validator.rb

19 lines
515 B
Ruby
Raw Normal View History

2015-12-23 02:04:40 +05:30
# EmailValidator
#
2014-09-02 18:07:02 +05:30
# Based on https://github.com/balexand/email_validator
2015-04-26 12:48:37 +05:30
#
2014-09-02 18:07:02 +05:30
# Extended to use only strict mode with following allowed characters:
# ' - apostrophe
#
# See http://www.remote.org/jochen/mail/info/chars.html
#
class EmailValidator < ActiveModel::EachValidator
2015-12-23 02:04:40 +05:30
PATTERN = /\A\s*([-a-z0-9+._']{1,64})@((?:[-a-z0-9]+\.)+[a-z]{2,})\s*\z/i.freeze
2014-09-02 18:07:02 +05:30
def validate_each(record, attribute, value)
2015-12-23 02:04:40 +05:30
unless value =~ PATTERN
2014-09-02 18:07:02 +05:30
record.errors.add(attribute, options[:message] || :invalid)
end
end
end