Skip to content

Commit

Permalink
Added a more thorough email format validation regex for User
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertStevenson authored and mike-burns committed Dec 21, 2010
1 parent 94d679c commit 67344d7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/clearance/user.rb
Expand Up @@ -50,7 +50,7 @@ def self.included(model)
model.class_eval do
validates_presence_of :email, :unless => :email_optional?
validates_uniqueness_of :email, :case_sensitive => false, :allow_blank => true
validates_format_of :email, :with => %r{.+@.+\..+}, :allow_blank => true
validates_format_of :email, :with => %r{^[a-z0-9!#\$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#\$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$}i, :allow_blank => true

validates_presence_of :password, :unless => :password_optional?
validates_confirmation_of :password
Expand Down
4 changes: 4 additions & 0 deletions test/models/user_test.rb
Expand Up @@ -12,7 +12,11 @@ class UserTest < ActiveSupport::TestCase
context "When signing up" do
should validate_presence_of(:email)
should validate_presence_of(:password)
should allow_value("foo@example.co.uk").for(:email)
should allow_value("foo@example.com").for(:email)
should_not allow_value("foo@").for(:email)
should_not allow_value("foo@example..com").for(:email)
should_not allow_value("foo@.example.com").for(:email)
should_not allow_value("foo").for(:email)
should_not allow_value("example.com").for(:email)

Expand Down

0 comments on commit 67344d7

Please sign in to comment.