Skip to content

Instantly share code, notes, and snippets.

@rbmrclo
Created May 22, 2014 05:57
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 rbmrclo/e52fbc14ec33c19263ad to your computer and use it in GitHub Desktop.
Save rbmrclo/e52fbc14ec33c19263ad to your computer and use it in GitHub Desktop.
Email validatior
class EmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
record.errors[attribute] << (options[:message] || 'is not an email')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment