clearance icon indicating copy to clipboard operation
clearance copied to clipboard

Refactor Clearance::User::Validations to use a more thorough email format validation regex

Open RobertStevenson opened this issue 15 years ago • 1 comments

Currently, the Clearance::User::Validations module uses the following for email format validation:

validates_format_of       :email, :with => %r{.+@.+\..+}, :allow_blank => true

Unfortunately, this is not a very thorough email format validation regex and allows emails addresses such as [email protected] and [email protected] to pass validation. I would like to see the email format validation regex suggested by http://www.regular-expressions.info/email.html used instead (Includes the addition of ^ and $ as well as the case-insensitive flag at the end) :

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   

The commit/code for this change can be found here: https://github.com/RobertStevenson/clearance/commit/2ce9c63853be8ca5fda2f710a57f3d0f181a6313

RobertStevenson avatar Dec 18 '10 21:12 RobertStevenson

Merged into master. Thanks!

mike-burns avatar Dec 21 '10 21:12 mike-burns