This project is archived and is in readonly mode.
validates_email
Reported by Stijn Mathysen | December 20th, 2008 @ 12:28 PM | in 2.x
I find myself copying the same regex over and over again to do email validates. And most of the times the regex that I use is not checking everything.
So I digged a little deeper and found a regex that matches all the rules on email validation and added it as a new validator.
class Person < ActiveRecord::Base
validates_email :email
end
Comments and changes to this ticket
-
Frederick Cheung December 20th, 2008 @ 03:30 PM
You're missing several top level domains, which sort of illustrates the futility of trying to be this explicit (especially now that icann will soon be having a far more open process for tld creation). You're far better off with a very simplistic regex and then actually sending the person a confirmation email
-
josh December 20th, 2008 @ 04:27 PM
I think this is a little to domain specific, but I think we compromise by just adding an ActiveRecord::Validations::EmailAddressRegexp constant.
-
ronin-41439 (at lighthouseapp) December 20th, 2008 @ 06:39 PM
Hey Guys,
thanks for the feedback! Seems that there are two options; * adjust the domain-name check * add a constant as Joshua suggests
I created a new patch that checks the top-level domainname to be 2 characters or more. Maybe that will get the patch accepted :-D?
Since this is my first patch; would you suggest opening up a new ticket with the new patch or add it to this ticket as I'm doing now?
Joshua; with "domain specific"; do you mean that checking email is too domain specific, or that the regex is too domain specific (sorry my English isn't that good :-s)
Thanks guys, hope you like the new patch.
Stijn
-
Pratik December 21st, 2008 @ 04:04 PM
- Assigned user set to Pratik
- State changed from new to wontfix
I really think this belongs to plugin. I'm sure there are existing plugins that does the same thing. Hopefully, we'll soon have something like http://github.com/leethal/active... which will make things a lot easier.
Having said that, I like Josh's idea too. So if there is an rfc compliant regexp for this, I'd be favor of having that in core.
Closing till we have a new patch.
Thanks.
-
Pratik December 21st, 2008 @ 04:05 PM
Stijn, if you need any sort of help - please feel free to catch me ("lifo") on irc ( irc.freenode.net - #rails-contrib ).
Thanks for your time!
-
ronin-41439 (at lighthouseapp) December 21st, 2008 @ 07:29 PM
Hey guys,
wow, thanks for the great replies and thanks for the support. Although this patch isn't going to be accepted, I still feel like I've contributed to something ;-)
Implementing an rfc compliant regex won't solve the problem (for more info, read here: http://www.regular-expressions.i.... But, if you want to use the ported regex from my latest patch, please do :-)
Cheers,
Stijn
-
Jeff Kreeftmeijer November 8th, 2010 @ 08:24 AM
- Tag cleared.
- Importance changed from to Low
Automatic cleanup of spam.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>