Rajinder Yadav
2010-Mar-10 11:46 UTC
Is there a rails way to validate format of an email address?
How can I validate and email address without using complex reg-ex is there a simple rails way to do this? -- Kind Regards, Rajinder Yadav -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Robert Walker
2010-Mar-10 14:16 UTC
Re: Is there a rails way to validate format of an email addr
Rajinder Yadav wrote:> How can I validate and email address without using complex reg-ex is > there a simple rails way to do this?Are you nuts? That''s just the sort of thing Regexp was designed to do. And, it''s not really all that complex. The Rails docs even use email validation as the example for validates_format_of so it''s not like you have to write the "complex" regex yourself. Just copy-and-paste: class Person < ActiveRecord::Base validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :on => :create end -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Mar-10 15:09 UTC
Re: Is there a rails way to validate format of an email addr
Robert Walker wrote:> Rajinder Yadav wrote: >> How can I validate and email address without using complex reg-ex is >> there a simple rails way to do this? > > Are you nuts? That''s just the sort of thing Regexp was designed to do. > And, it''s not really all that complex.Yes it is. The *only* correct regexps I am aware of for e-mail addresses are on the order of a page in length. All shorter regexps reject some valid e-mail addresses. Just check for the . and @, and trust the user for the rest.> The Rails docs even use email > validation as the example for validates_format_of so it''s not like you > have to write the "complex" regex yourself. Just copy-and-paste: > > class Person < ActiveRecord::Base > validates_format_of :email, :with => > /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :on => :create > endThat regexp is just a simple example. It isn''t even close to covering all valid e-mail addresses. Don''t use it. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Robert Walker
2010-Mar-10 15:34 UTC
Re: Is there a rails way to validate format of an email addr
Marnen Laibow-Koser wrote:> Robert Walker wrote: >> Rajinder Yadav wrote: >>> How can I validate and email address without using complex reg-ex is >>> there a simple rails way to do this? >> >> Are you nuts? That''s just the sort of thing Regexp was designed to do. >> And, it''s not really all that complex. > > Yes it is. The *only* correct regexps I am aware of for e-mail > addresses are on the order of a page in length. All shorter regexps > reject some valid e-mail addresses.Thanks Marnen. I stand corrected. However, just to clarify, are you saying that Regexp is still the best approach? Given that what you''re saying is true, which I''m sure it is, then I could imagine that performing this validation without using Regexp would be even more complex and require quite a bit more code. -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Aldric Giacomoni
2010-Mar-10 16:27 UTC
Re: Is there a rails way to validate format of an email addr
Robert Walker wrote:> Marnen Laibow-Koser wrote: >> Robert Walker wrote: >>> Rajinder Yadav wrote: >>>> How can I validate and email address without using complex reg-ex is >>>> there a simple rails way to do this? >>> >>> Are you nuts? That''s just the sort of thing Regexp was designed to do. >>> And, it''s not really all that complex. >> >> Yes it is. The *only* correct regexps I am aware of for e-mail >> addresses are on the order of a page in length. All shorter regexps >> reject some valid e-mail addresses. > > Thanks Marnen. I stand corrected. > > However, just to clarify, are you saying that Regexp is still the best > approach? Given that what you''re saying is true, which I''m sure it is, > then I could imagine that performing this validation without using > Regexp would be even more complex and require quite a bit more code.The best approach is to download a plugin for email validation, because someone, somewhere, has already done all the work ;-) -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Philip Hallstrom
2010-Mar-10 16:37 UTC
Re: Re: Is there a rails way to validate format of an email addr
> Robert Walker wrote: >> Marnen Laibow-Koser wrote: >>> Robert Walker wrote: >>>> Rajinder Yadav wrote: >>>>> How can I validate and email address without using complex reg- >>>>> ex is >>>>> there a simple rails way to do this? >>>> >>>> Are you nuts? That''s just the sort of thing Regexp was designed >>>> to do. >>>> And, it''s not really all that complex. >>> >>> Yes it is. The *only* correct regexps I am aware of for e-mail >>> addresses are on the order of a page in length. All shorter regexps >>> reject some valid e-mail addresses. >> >> Thanks Marnen. I stand corrected. >> >> However, just to clarify, are you saying that Regexp is still the >> best >> approach? Given that what you''re saying is true, which I''m sure it >> is, >> then I could imagine that performing this validation without using >> Regexp would be even more complex and require quite a bit more code. > > The best approach is to download a plugin for email validation, > because > someone, somewhere, has already done all the work ;-)Several some ones... http://agilewebdevelopment.com/plugins/validates_as_email http://agilewebdevelopment.com/plugins/validates_as_email_address http://agilewebdevelopment.com/plugins/validates_email_format_of -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Robert Walker
2010-Mar-10 16:58 UTC
Re: Re: Is there a rails way to validate format of an email
Philip Hallstrom wrote:> http://agilewebdevelopment.com/plugins/validates_email_format_ofThis one does look interesting. Even has support for checking DNS MX records. I see more clearly now what Marnen was talking about. This plugin certainly does use Regexp, and I have to admit it is quite complex. :-) -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Rajinder Yadav
2010-Mar-10 17:03 UTC
Re: Re: Is there a rails way to validate format of an email addr
Philip Hallstrom wrote:>> Robert Walker wrote: >>> Marnen Laibow-Koser wrote: >>>> Robert Walker wrote: >>>>> Rajinder Yadav wrote: >>>>>> How can I validate and email address without using complex reg-ex is >>>>>> there a simple rails way to do this? >>>>> >>>>> Are you nuts? That''s just the sort of thing Regexp was designed to do. >>>>> And, it''s not really all that complex. >>>> >>>> Yes it is. The *only* correct regexps I am aware of for e-mail >>>> addresses are on the order of a page in length. All shorter regexps >>>> reject some valid e-mail addresses. >>> >>> Thanks Marnen. I stand corrected. >>> >>> However, just to clarify, are you saying that Regexp is still the best >>> approach? Given that what you''re saying is true, which I''m sure it is, >>> then I could imagine that performing this validation without using >>> Regexp would be even more complex and require quite a bit more code. >> >> The best approach is to download a plugin for email validation, because >> someone, somewhere, has already done all the work ;-) > > > Several some ones... > > http://agilewebdevelopment.com/plugins/validates_as_email > http://agilewebdevelopment.com/plugins/validates_as_email_address > http://agilewebdevelopment.com/plugins/validates_email_format_of >Thanks Philip =) -- Kind Regards, Rajinder Yadav -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Mar-10 17:12 UTC
Re: Is there a rails way to validate format of an email addr
Aldric Giacomoni wrote:> Robert Walker wrote: >> Marnen Laibow-Koser wrote: >>> Robert Walker wrote: >>>> Rajinder Yadav wrote: >>>>> How can I validate and email address without using complex reg-ex is >>>>> there a simple rails way to do this? >>>> >>>> Are you nuts? That''s just the sort of thing Regexp was designed to do. >>>> And, it''s not really all that complex. >>> >>> Yes it is. The *only* correct regexps I am aware of for e-mail >>> addresses are on the order of a page in length. All shorter regexps >>> reject some valid e-mail addresses. >> >> Thanks Marnen. I stand corrected. >> >> However, just to clarify, are you saying that Regexp is still the best >> approach? Given that what you''re saying is true, which I''m sure it is, >> then I could imagine that performing this validation without using >> Regexp would be even more complex and require quite a bit more code. > > The best approach is to download a plugin for email validation, because > someone, somewhere, has already done all the work ;-)I wouldn''t trust those plugins without inspecting their algorithms. I would probably use something like the following regex: /^.+@.+\..+$/ This checks that it''s of the form "something-f52GMkFzgz+DnLrLYhipotkegs52MxvZ@public.gmane.org", but performs no further validation. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Philip Hallstrom
2010-Mar-10 18:01 UTC
Re: Re: Is there a rails way to validate format of an email addr
> Aldric Giacomoni wrote: >> Robert Walker wrote: >>> Marnen Laibow-Koser wrote: >>>> Robert Walker wrote: >>>>> Rajinder Yadav wrote: >>>>>> How can I validate and email address without using complex reg- >>>>>> ex is >>>>>> there a simple rails way to do this? >>>>> >>>>> Are you nuts? That''s just the sort of thing Regexp was designed >>>>> to do. >>>>> And, it''s not really all that complex. >>>> >>>> Yes it is. The *only* correct regexps I am aware of for e-mail >>>> addresses are on the order of a page in length. All shorter >>>> regexps >>>> reject some valid e-mail addresses. >>> >>> Thanks Marnen. I stand corrected. >>> >>> However, just to clarify, are you saying that Regexp is still the >>> best >>> approach? Given that what you''re saying is true, which I''m sure it >>> is, >>> then I could imagine that performing this validation without using >>> Regexp would be even more complex and require quite a bit more code. >> >> The best approach is to download a plugin for email validation, >> because >> someone, somewhere, has already done all the work ;-) > > I wouldn''t trust those plugins without inspecting their algorithms. I > would probably use something like the following regex: > /^.+@.+\..+$/ > > This checks that it''s of the form "something-f52GMkFzgz+DnLrLYhipotkegs52MxvZ@public.gmane.org", but > performs no further validation.Good point. It annoys me to no end when I can''t enter philip+sitename-LSG90OXdqQE@public.gmane.org as a valid email address. Seems this works about half the time. The bottom line is if you are really concerned about getting a valid email address, the only way to completely verify it is to send them an email and make them confirm it via a link in that email. Headache, yeah, but it works. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
kannav rajeev
2010-Mar-12 05:51 UTC
Re: Is there a rails way to validate format of an email address?
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :on => :create end On Wed, Mar 10, 2010 at 5:16 PM, Rajinder Yadav <devguy.ca-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> How can I validate and email address without using complex reg-ex is there > a simple rails way to do this? > > > -- > Kind Regards, > Rajinder Yadav > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- Thanks: Rajeev sharma -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.