Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

validates_email

#1606

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

Reported by Stijn Mathysen · December 20th, 2008 @ 12:28 PM

State: wontfix
Milestone: 2.x
Assigned to: Pratik Pratik
Importance: Low

Activity

  1. Frederick Cheung
    Frederick Cheung

    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

    December 20th, 2008 @ 03:30 PM

  2. josh
    josh

    I think this is a little to domain specific, but I think we compromise by just adding an ActiveRecord::Validations::EmailAddressRegexp constant.

    December 20th, 2008 @ 04:27 PM

  3. ronin-41439 (at lighthouseapp)
    ronin-41439 (at lighthouseapp)

    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

    December 20th, 2008 @ 06:39 PM

  4. Pratik
    Pratik
    • 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.

    December 21st, 2008 @ 04:04 PM

  5. Pratik
    Pratik

    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!

    December 21st, 2008 @ 04:05 PM

  6. ronin-41439 (at lighthouseapp)
    ronin-41439 (at lighthouseapp)

    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

    December 21st, 2008 @ 07:29 PM

  7. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • Tag cleared.
    • Importance changed from to Low

    Automatic cleanup of spam.

    November 8th, 2010 @ 08:24 AM

  8. af001
    af001

    私の中で、総合評価のとっても低いアバアバクロホリスタークロ銀座店。アバクロは大好きなんですけどね。一昨日の東京駅付近での打ち合わせの後、散歩がてら久々に行ってきました。そしたらビックリ!相変わらアバクロず、踊っているだけの店員さんとかもいましたが、

    May 5th, 2011 @ 03:01 AM