How can I validate and email address without using complex reg-ex is
there a simple rails way to do this?
–
Kind Regards,
Rajinder Y.
How can I validate and email address without using complex reg-ex is
there a simple rails way to do this?
–
Kind Regards,
Rajinder Y.
Rajinder Y. 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
Robert W. wrote:
Rajinder Y. 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
end
That regexp is just a simple example. It isn’t even close to covering
all valid e-mail addresses. Don’t use it.
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
Marnen Laibow-Koser wrote:
Robert W. wrote:
Rajinder Y. 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.
And, it’s not really all that complex.
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
Robert W. wrote:
Marnen Laibow-Koser wrote:
Robert W. wrote:
Rajinder Y. 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
Philip H. wrote:
http://agilewebdevelopment.com/plugins/validates_email_format_of
This 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.
Aldric G. wrote:
Robert W. wrote:
Marnen Laibow-Koser wrote:
Robert W. wrote:
Rajinder Y. 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 “[email protected]”, but
performs no further validation.
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
to do.
best
would probably use something like the following regex:
/^.+@.+…+$/This checks that it’s of the form “[email protected]”, but
performs no further validation.
Good point. It annoys me to no end when I can’t enter
[email protected]
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.
Philip H. wrote:
Yes it is. The only correct regexps I am aware of for e-mail
The best approach is to download a plugin for email validation, because
someone, somewhere, has already done all the workSeveral 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 Y.
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 Y. [email protected]
wrote:
“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][email protected]
.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
–
Thanks:
Rajeev sharma
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs