Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-12-02 02:46:00 +0300
committerRobert Speicher <rspeicher@gmail.com>2015-12-08 00:57:26 +0300
commitb3200c8c44f2351d88d5d78d7ded3ac06001bd7c (patch)
tree0873ea7a0f3bc11096ae49224db15a00e2c21959 /app/validators
parentd5ea93469b4ec95916361c61876c949f60539211 (diff)
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