Skip to content

Instantly share code, notes, and snippets.

@Imranshaikh
Created May 14, 2013 04:10
Show Gist options
  • Save Imranshaikh/5573635 to your computer and use it in GitHub Desktop.
Save Imranshaikh/5573635 to your computer and use it in GitHub Desktop.
For invalid email in ruby on rails debugging
class User < ActiveRecord::Base
attr_accessible :email, :name, :password, :password_confirmation
has_secure_password
before_save{ self.email.downcase! }
before_save { |user| user.email = email.downcase }
validates(:name, presence: true, length: { maximum: 50 } )
VALID_EMAIL_REGEX = /\A[\W+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true,
format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
validates :password, presence: true, length: { minimum: 6 }
validates :password_confirmation, presence: true
end
@BilalBudhani
Copy link

Try this
validates_format_of :email, :with => /\A[^@]+@([^@\.]+\.)+[^@\.]+\z/

@Imranshaikh
Copy link
Author

Yes, bilal bhai successfully inserted.... Thanks alot :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment