Forum: Ruby on Rails validate email address

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
josh (Guest)
on 2007-03-26 20:09
What is the best way to validate an email address?

I have been unable to fnd a validates_email address method which seems a
bit strange for rails
david (Guest)
on 2007-03-26 20:17
josh wrote:
> What is the best way to validate an email address?
>
> I have been unable to fnd a validates_email address method which seems a
> bit strange for rails

i use this:
  validates_format_of :email,
                      :with =>
/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
josh (Guest)
on 2007-03-26 22:43
david wrote:
> josh wrote:
>> What is the best way to validate an email address?
>>
>> I have been unable to fnd a validates_email address method which seems a
>> bit strange for rails
>
> i use this:
>   validates_format_of :email,
>                       :with =>
> /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i

thanks that seems to ahve worked fine.
Althrough it seems a bit strange how rails does not have this in the lib
David A. Black (Guest)
on 2007-03-26 22:59
(Received via mailing list)
Hi --

On 3/26/07, josh <removed_email_address@domain.invalid> wrote:
> >                       :with =>
> > /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
>
> thanks that seems to ahve worked fine.
> Althrough it seems a bit strange how rails does not have this in the lib

If Rails were to have an email address validator, it would have to
cover all of RFC 2822, which this regex doesn't.


David

--
Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black)
   (See what readers are saying!  http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)
Dale M. (Guest)
on 2007-03-26 23:51
(Received via mailing list)
On Mar 26, 1:58 pm, "David A. Black" <removed_email_address@domain.invalid> 
wrote:
> > >> I have been unable to fnd a validates_email address method which seems a
> If Rails were to have an email address validator, it would have to
> cover all of RFC 2822, which this regex doesn't.

I know the book "Master Regular Expressions" by Jeffrey E.F. Friedl
includes an example to parse an email address that is 6598 bytes long
(see Appendix B). And I remember reading that it didn't handle all
possible nesting cases.
Wes (Guest)
on 2007-03-27 00:10
(Received via mailing list)
This topic is locked and can not be replied to.