Skip to content
Snippets Groups Projects
Commit 96e51a03 authored by Robert Speicher's avatar Robert Speicher
Browse files

Minor EmailValidator refactor

parent e48391b8
No related branches found
No related tags found
No related merge requests found
# EmailValidator
#
# Based on https://github.com/balexand/email_validator
#
# Extended to use only strict mode with following allowed characters:
Loading
Loading
@@ -6,15 +8,10 @@
# See http://www.remote.org/jochen/mail/info/chars.html
#
class EmailValidator < ActiveModel::EachValidator
@@default_options = {}
def self.default_options
@@default_options
end
PATTERN = /\A\s*([-a-z0-9+._']{1,64})@((?:[-a-z0-9]+\.)+[a-z]{2,})\s*\z/i.freeze
 
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
unless value =~ PATTERN
record.errors.add(attribute, options[:message] || :invalid)
end
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment