Re: Email Verfication Regular Expression

From: Steve Atkins <steve(at)blighty(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Email Verfication Regular Expression
Date: 2005-09-07 19:21:45
Message-ID: 20050907192145.GA30366@gp.word-to-the-wise.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Sep 07, 2005 at 11:17:10AM -0400, Brad Nicholson wrote:
> Does anybody have regular expression handy to verfiy email addresses?

It's not possible to validate an email address with a regex. If
you're prepared to handwave over things like whitespace and
embedded comments you can validate with a scary big regex.
Take a look at Mail::RFC822::Address from CPAN.

But, depending on what you're doing, validation may not be a good
idea. There are email addresses that are syntactically invalid that
are deliverable and in active use. You might want to look at
just doing some basic sanity checking instead, rather than
full validation - something like

/^[^(at)]*@(?:[^(at)]*\(dot))?[a-z0-9-_]+\.(?:a[defgilmnoqrstuwz]|b[abdefghijmnorstvwyz]|c[acdfghiklmnoruvxyz]|d[ejkmoz]|e[ceghrst]|f[ijkmorx]|g[abdefhilmnpqrstuwy]|h[kmnrtu]|i[delnoqrst]|j[mop]|k[eghimnprwyz]|l[abcikrstuvy]|m[acdghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrtwy]|qa|r[eouw]|s[abcdeghijklmnortvyz]|t[cdfghjkmnoprtvwz]|u[agkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw]|edu|com|net|org|gov|mil|info|biz|coop|museum|aero|name|pro)$/

This'll exclude email addresses like tv(at)tv, but the owners of such are used
to their being rejected, and it saves you from a lot of the usual miskeyed
addresses.

Cheers,
Steve

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Michael Fuhr 2005-09-07 19:24:54 Re: back references using regex
Previous Message J 2005-09-07 19:17:46 max number of triggers in a table