Skip to content

Instantly share code, notes, and snippets.

@breinz
Created August 2, 2013 14:21
Show Gist options
  • Save breinz/6140232 to your computer and use it in GitHub Desktop.
Save breinz/6140232 to your computer and use it in GitHub Desktop.
# config/initializers/email_validation.rb
Rails.application.config.before_initialize do
email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
end
# app/models/user.rb
class User < ActiveRecord::Base
attr_accessible :email
validates :email, :format => { :with => email_regex }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment