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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email address validation 2

Status
Not open for further replies.

Fris

Programmer
Jun 23, 2003
22
US
I have incorporated this code (found on Tek-Tips but I can't remember who originated it) into my form and it works well if an invalid address has been entered:

str=form1.Email.value;
filter=/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str)!=true)
{
alert("Please input a valid email address!");
event.returnValue=false;
return

What would be the best way to manipulate this code to allow for a totally blank field? I have tried several things with no success.

Thanks!
Christine
 
before this conditional statement start a new one
if(frmField.value == "") {
return true;
}

that will return control if the field is emnpty and not run the regex test.


_____________________________________________________________________
[sub]Where have all my friends gone to????[/sub]
onpnt2.gif

 
Code:
if ( ( filter.test( str ) != true ) && str.length != 0 )
should work. Haven't tested it though. :)
 
Thank you both! onput's answer got here first, I tried it and it worked. But...thank's for your input, BoyHope!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top