Re: Email Verfication Regular Expression - Mailing list pgsql-general

From Steve Atkins
Subject Re: Email Verfication Regular Expression
Date
Msg-id 20050907192145.GA30366@gp.word-to-the-wise.com
Whole thread Raw
In response to Email Verfication Regular Expression  (Brad Nicholson <bnichols@ca.afilias.info>)
Responses Re: Email Verfication Regular Expression
Re: Email Verfication Regular Expression
Re: Email Verfication Regular Expression
List 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


/^[^@]*@(?:[^@]*\.)?[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@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


pgsql-general by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: back references using regex
Next
From: Bruno Wolff III
Date:
Subject: Re: Email Verfication Regular Expression