Permalink
Browse files

Added a more thorough email format validation regex for User

  • Loading branch information...
1 parent 94d679c commit 67344d73a7a3644df695ad64d4714b4545694f04 @RobertStevenson RobertStevenson committed with mike-burns Dec 18, 2010
Showing with 5 additions and 1 deletion.
  1. +1 −1 lib/clearance/user.rb
  2. +4 −0 test/models/user_test.rb
View
@@ -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
View
@@ -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)

0 comments on commit 67344d7

Please sign in to comment.