Skip to content

Instantly share code, notes, and snippets.

@ankane
Created May 26, 2011 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ankane/993697 to your computer and use it in GitHub Desktop.
Save ankane/993697 to your computer and use it in GitHub Desktop.
class EmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
record.errors[attribute] << (options[:message] || "is not an email") unless
value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment