Skip to content

Instantly share code, notes, and snippets.

@Fivell
Created April 7, 2012 10:17
Show Gist options
  • Save Fivell/2327193 to your computer and use it in GitHub Desktop.
Save Fivell/2327193 to your computer and use it in GitHub Desktop.
EmailValidator < ActiveModel::EachValidator
class EmailValidator < ActiveModel::EachValidator
EmailAddress = /\A[\w!\#$%&'*+\/=?^_\`{|}~-]+(?:\.[\w!\#$%&'*+\/=?^_\`{|}~-]+)*@(?:\w(?:[\w-]*\w)?\.)+\w(?:[\w-]*[\w])?\z/
def validate_each(record, attribute, value)
unless value =~ EmailAddress
record.errors[attribute] << (options[:message] || "is not valid")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment