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 gkittelson 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

Status
Not open for further replies.

ami7

Programmer
Oct 3, 2002
48
GB
Hi all,

In my .aspx page i have a textbox in which email address will be entered.
For validating the email address i have got this javascript.
But how to implement this here.
I know there is a property in the custom validator to enter
ClientValidationFunction.

Can anyone tell me how to use this code in my appln.


javacode:
function validEmail(objEmail) {
var strEmail = ""+objEmail.value;
var errorStr = "";
var atCount = 0;
for (var i=0;i<strEmail.length;i++) {
if (strEmail.charAt(i) == &quot;@&quot;) atCount++;
}

var emailFilter=/^.+@.+\..{2,3}$/;
if (!(emailFilter.test(strEmail)) || atCount > 1 || strEmail.indexOf(&quot;..&quot;)!=-1) {
errorStr = &quot;Please enter a valid email address.\n&quot;;
alert(errorStr);
highlightField(objEmail);
return false;
}

var illegalChars= /[\(\)\ \{\}\!\%\£\¬\`\'\?\$\^\&\*\|\#\=\+\<\>\,\;\:\\\/\&quot;\[\]]/;
if (strEmail.match(illegalChars)) {
errorStr = &quot;The email address contains illegal characters.\n&quot;;
alert(errorStr);
highlightField(objEmail);
return false;
}
return true;
}
Thanks,
ami.
 
Instead of using a custom validator, use a regular expression validator. You just tell the validator which field you want it to validate, put in the regex as one of the validator's properties, and let 'er rip.

D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top