Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validate multiple email addresses... 1

Status
Not open for further replies.

mat41

Programmer
Mar 7, 2004
91
AU
Hello JS ers

I use this code to validate an email address:
-------------------------------------
email=document.addUser.eMail.value;
var expression=/^([a-zA-Z0-9\-\._]+)@(([a-zA-Z0-9\-_]+\.)+)([a-z]{2,3})$/;
if(!(expression.test(email)) )
{
alert("Please enter a valid email address (50 chars max)");
document.addUser.eMail.select();
document.addUser.eMail.focus();
return false;
}
-------------------------------------

It works very nicely. I would help altering it to validate several addresses. These addresses wil come in the form of a commer delimites string from an <input type="text"> form element.

Im am no JS guy. I would appreciate some assistance.

TYIA
 
I would try this.
[tt]
var expression=/^[blue]([/blue]([a-zA-Z0-9\-\._]+)@(([a-zA-Z0-9\-_]+\.)+)([a-z]{2,3})[blue](,(?!$))?)+[/blue]$/;
[/tt]
 
tsuji

Outstanding. I am an ASP guy who spends allot of time at the wrox forum solving ASP issues. My JS is a bit basic especially REG EX syntax.

Whats the chances of making this work:
1..Using a semicolon or a commer as the address seperator (presently it works with a commer but not semi colon)

2..Allowing a space between the seperator and the following address (not essential but would be a nice feature)

Thank you for your time, it is much appreciated!!
 
Thanks! To relax the separator, it is along this line.
[1] Allowing comma and semi-colon, it is to replace "," by "[,;]".
[2] Allowing a space, in particular allowing "one" space only after the separator but [2a] disallowing more than one space and [2b] any space before the separator, it will be to replace "[,;]" by "[,;]\W?". (Further relaxation which might not be desirable would be for instance "\W?[,;]\W?" or much more "\W*[,;]\W*" along the same reasoning.)
[tt]
var expression=/^(([a-zA-Z0-9\-\._]+)@(([a-zA-Z0-9\-_]+\.)+)([a-z]{2,3})([blue][,;]\W?[/blue](?!$))?)+$/;[/tt]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top