Mar
25
Filed under: Asides | March 25th, 2005

Validate Emails

How to REALLY validate emails.

No related posts.

13 Responses

  • Eric Meyer | March 25th, 2005 @ 11:13 am | Reply

    Well, that’s that. I’ve finally seen something that looks more like line noise than Perl does.

  • Andy Skelton | March 25th, 2005 @ 11:16 am | Reply

    Woah. Have you ever seen a regex that big? Somebody call a priest.

  • BenJ | March 25th, 2005 @ 11:40 am | Reply

    *phew*! I’m glad someone else took the time — now I can spend it at the bar.

  • Noel | March 25th, 2005 @ 12:02 pm | Reply

    The most insane thing I’ve ever seen.

  • Donncha | March 25th, 2005 @ 12:26 pm | Reply

    Yes, but when the next person quoted the entire thing when replying with a one line comment on how incredible that regex was..
    I’m glad commenting on blogs doesn’t automatically quote the post!

  • Denis de Bernardy | March 25th, 2005 @ 4:59 pm | Reply

    Geez… Frankly…:

    ([\w]+\.)*([\w]+)@([\w]+)(\.[\w]+)+

    is good enough. it’s not as of spammers were trying to insert emails as $^ù_`è.#’@&”~.com

  • Denis de Bernardy | March 25th, 2005 @ 5:00 pm | Reply

    err, even:

    (\w+\.)*(\w+)@(\w+)(\.\w+)+

    but then, you go the point

  • Mr. Dew | March 26th, 2005 @ 12:32 am | Reply

    That’s the longest regex I’ve seen!

  • Jonathan Fenocchi | March 26th, 2005 @ 5:34 am | Reply

    Wow, that is long. I haven’t tested which works better, but this one has always worked fine for me:


    /[^\x00-\x20()@,;:".[\]\x7f-\xff]+(?:\.[^\x00-\x20()@,;:".[\]\x7f-\xff]+)*\@[^\x00-\x20()@,;:".[\]\x7f-\xff]+(?:\.[^\x00-\x20()@,;:".[\]\x7f-\xff]+)+/i

  • Jonathan Fenocchi | March 26th, 2005 @ 5:34 am | Reply

    Whoops, sorry about that horizontal scrollbar. (Can I edit my own comments somehow?)

  • Priyadi | March 27th, 2005 @ 4:12 am | Reply

    I believe it is not how to match email address, but how to match the whole RFC822 address which includes one or more email address. An email address looks like this: john@example.com. But an RFC822 address may look something like “John Doe” <john@example.com>.

  • Observer | March 27th, 2005 @ 6:01 am | Reply

    Wow: Is it before or after RSA encryption?

  • Jim | March 27th, 2005 @ 11:13 am | Reply

    Heh. Now he has two problems.

    There are lots of valid email addresses that typical regexps don’t catch. IIRC, the following is a valid email address: “a b c”@[127.0.0.1] – a regexp is really not enough to validate an email address, because you end up with a monstrosity like this (with all respect to the author).

Share your thoughts