summaryrefslogtreecommitdiff
path: root/app/validators
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-12-01 18:46:00 -0500
committerRobert Speicher <rspeicher@gmail.com>2015-12-07 16:57:26 -0500
commitb3200c8c44f2351d88d5d78d7ded3ac06001bd7c (patch)
tree0873ea7a0f3bc11096ae49224db15a00e2c21959 /app/validators
parentd5ea93469b4ec95916361c61876c949f60539211 (diff)
downloadgitlab-ce-b3200c8c44f2351d88d5d78d7ded3ac06001bd7c.tar.gz
Move EmailValidator to app/validators
Diffstat (limited to 'app/validators')
-rw-r--r--app/validators/email_validator.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/app/validators/email_validator.rb b/app/validators/email_validator.rb
new file mode 100644
index 00000000000..f509f0a5843
--- /dev/null
+++ b/app/validators/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