diff options
author | Marin Jankovski <marin@gitlab.com> | 2014-06-11 13:22:56 +0200 |
---|---|---|
committer | Marin Jankovski <marin@gitlab.com> | 2014-06-11 13:36:30 +0200 |
commit | f43e41973f912588d7af23a5575ede94a88d3a5d (patch) | |
tree | db4c4aa9bdd71b1e60c9b64b8ac97a9a696ad872 /lib/email_validator.rb | |
parent | e57fdc1190af582544154b77f0271ef9f206bc47 (diff) | |
download | gitlab-ce-f43e41973f912588d7af23a5575ede94a88d3a5d.tar.gz |
Test for the apostrophe in the email
Diffstat (limited to 'lib/email_validator.rb')
-rw-r--r-- | lib/email_validator.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/email_validator.rb b/lib/email_validator.rb new file mode 100644 index 00000000000..0a67ebcd795 --- /dev/null +++ b/lib/email_validator.rb @@ -0,0 +1,21 @@ +# Based on https://github.com/balexand/email_validator +# +# 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 + @@default_options = {} + + def self.default_options + @@default_options + end + + def validate_each(record, attribute, value) + options = @@default_options.merge(self.options) + unless value =~ /\A\s*([-a-z0-9+._']{1,64})@((?:[-a-z0-9]+\.)+[a-z]{2,})\s*\z/i + record.errors.add(attribute, options[:message] || :invalid) + end + end +end |