gitlab-org--gitlab-foss/app/validators/email_validator.rb

19 lines
515 B
Ruby
Raw Normal View History

2015-12-01 19:21:45 -05:00
# EmailValidator
#
# Based on https://github.com/balexand/email_validator
2015-02-03 00:31:03 -05:00
#
# 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-01 19:21:45 -05:00
PATTERN = /\A\s*([-a-z0-9+._']{1,64})@((?:[-a-z0-9]+\.)+[a-z]{2,})\s*\z/i.freeze
def validate_each(record, attribute, value)
2015-12-01 19:21:45 -05:00
unless value =~ PATTERN
record.errors.add(attribute, options[:message] || :invalid)
end
end
end