You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
544 B

EmailAddress::Config.configure(local_format: :conventional)
class EmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return unless value
if value.is_a?(Array)
value.each { |v| validate_value(record, attribute, v) }
else
validate_value(record, attribute, value)
end
end
private
def validate_value(record, attribute, value)
unless EmailAddress.valid?(value)
record.errors[attribute] << (options[:message] || "#{value} is not a valid email")
end
end
end