Forum Moderators: open

Message Too Old, No Replies

Javascript expression for validating multiple email addresses

regexp, javascript only (not perl/cgi), validation

         

Garoun

4:33 pm on Oct 22, 2004 (gmt 0)

10+ Year Member



I am working on an emailing routine for a project I'm doing and currently have a problem using a javascript regular expression to check for certain criteria.

Sample Input:

bleh.wrawr@test.com;wrawr.bleh@test.comwrawr.bleh@test.com
-------
Criteria to be met:

1) If there is only one '@' is present then I assume it is only one email address and run it through my address validater
2) If more then one '@' is present then there must be a ';' between each them (aka @*;*@ where * = any amount/type of character)
3) If there is more then one instance then the check must ensure that there is always a ';' between each pair of '@'
-------
Examples:

a@b.c = true
a@b.cd@e.f = false
a@b.c;d@e.f = true
a@b.c;d@e.fg.h@j = false
a@b.cd@e.f;g@h.i = false
a@b.c;d@e.f;g@h.i = true

Thanks in advance.

dcrombie

3:20 pm on Oct 25, 2004 (gmt 0)



I would first explode the string on ';' and then check that each element in the array is a valid email address.

;)

adni18

8:41 pm on Oct 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



...or you might want to try [javascript.internet.com...]