Am 26.09.2010 um 18:54 schrieb Nadal:

> I am working on a rails3 project. Is there a tool to validate the
> format of email address. It does not have to be fancy regex. Just a
> few simple validations. However I don't want to reinvent the wheel?

Using a regex to validate an email format is in most cases a bad idea, the 2 
proposed regexes won't for example recognize quoted local parts, which are 
valid (e.g. "f...@bar"@rails.info is a valid address). There's a 
validate_email_format_of plugin on github[1] which works fine on rails2, I 
think there is a branch/fork for rails3 somewhere too. Another method would be 
to just drop an EmailValidator into your lib so that you can reuse it at other 
places in your rails app, have a look at [2] (yes, it still is a regex and only 
matches what the RFC refers to as "addr-spec" as opposed to a "full" address, 
but a not-so-bad one).

Anyway, I'm a little surprised that rails3 having gone from TMail to Mail 
hasn't added a validator that would re-use the one already present in Mail…

Regards,

Felix


[1] http://github.com/alexdunae/validates_email_format_of
[2] http://lindsaar.net/2010/1/31/validates_rails_3_awesome_is_true

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to