2016-07-31 14:47:15 -05:00
|
|
|
class EmailFormatValidator < ActiveModel::EachValidator
|
|
|
|
def validate_each(record, attribute, value)
|
|
|
|
# EMAIL regex test
|
|
|
|
# (comma seperated) [any word combo] AT [any word combo] DOT [2 or more]
|
|
|
|
# me@no.yes.x == invalid
|
|
|
|
# some.thing+two@sub.domain.name == valid
|
|
|
|
|
|
|
|
results = value.to_s.split(',').map do |v|
|
|
|
|
(v.strip =~ /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i) || v.strip.blank?
|
|
|
|
end
|
|
|
|
|
|
|
|
if results.include?(false)
|
2016-08-01 16:43:05 -05:00
|
|
|
record.errors[attribute] << (options[:message] || "is not formatted properly")
|
2016-07-31 14:47:15 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|