PDA

View Full Version : Email validation routine


Alex Piotto
08-15-2002, 10:02 AM
Hi everybody!
I found the email validation routine below somewhere on the net, and seems to do the job very well... but ... if I try to validate an address like "alex21@yahoo.com" I get the alert from the second part of the script that the email address is invalid...

If I delete the 21 the email is ok.

the routine:
---------------------------
var emailregex = /^([a-z]+)([.,_,-]([0-9,a-z,A-Z]+))*@([a-z0-9]+)([.,_,-]([0-9,a-z,A-Z]+))*\.[a-z]{2,4}$/i
---------------------------

Why is this happening? How can I modify the routine?

Can somebody help me? I am just a beginner...

thanks

Alex :(

ShriekForth
08-15-2002, 05:04 PM
The problem appears to be in the first part of your statement.

([a-z]+)([.,_,-]([0-9,a-z,A-Z]+))

This will allow only aphas, followed by a . _ or - then any character. so if you had joe.21@my.com

make the first part of the statement accept the caps, and numbers as well..

/^([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*

Then your example will validate as you expect.

ShriekForth

jkd
08-15-2002, 05:11 PM
Use my take on the email validation regexp:

http://www.javascriptkit.com/script/script2/acheck.shtml

And more specifically:

/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i

:)

beetle
08-15-2002, 05:20 PM
I've found the email regex at webreference (http://www.webreference.com/js/column5/form.html) to be pretty good too.

Alex Piotto
08-15-2002, 05:46 PM
Well, thank to everybody answered!
This night I'll put myself on the job...
Hope to be useful another time...

Thanks again
Alex :)