Gossamer Forum
Home : General : Perl Programming :

emaill validation

Quote Reply
emaill validation
for years i have been using the following in my dbman def files to validate email addresses:

'.+@.+..+'

for the first time, someone entered a space in the email address and the db accepted it. the user didn't get an error until attempting to send an email to the invalid address. i found the following expression, which seems to work.

'^[-\w.]+@([A-z0-9][-A-z0-9]+\.)+[A-z]{2,4}$'

do you see any problems with it?

i'm actually amazed this hasn't come up before. thanks!
Quote Reply
Re: [delicia] emaill validation In reply to
Hi,

You may end up with problems on domains that have stuff like .co.uk, org.uk, etc. According to here:

http://www.regular-expressions.info/email.html

Code:
(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*
| "(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]
| \\[\x01-\x09\x0b\x0c\x0e-\x7f])*")
@ (?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?
| \[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}
(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:
(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]
| \\[\x01-\x09\x0b\x0c\x0e-\x7f])+)
\])

Blood complex! However, there is a simpler version which should do the trick for you:

Code:
[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?

Hope that helps Angelic

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] emaill validation In reply to
omg! thanks!