summaryrefslogtreecommitdiff
path: root/app/validators/email_validator.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/validators/email_validator.rb')
-rw-r--r--app/validators/email_validator.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/app/validators/email_validator.rb b/app/validators/email_validator.rb
new file mode 100644
index 00000000000..b35af100803
--- /dev/null
+++ b/app/validators/email_validator.rb
@@ -0,0 +1,18 @@
+# EmailValidator
+#
+# 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
+ PATTERN = /\A\s*([-a-z0-9+._']{1,64})@((?:[-a-z0-9]+\.)+[a-z]{2,})\s*\z/i.freeze
+
+ def validate_each(record, attribute, value)
+ unless value =~ PATTERN
+ record.errors.add(attribute, options[:message] || :invalid)
+ end
+ end
+end