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) == "@" atCount++;
}
var emailFilter=/^.+@.+\..{2,3}$/;
if (!(emailFilter.test(strEmail)) || atCount > 1 || strEmail.indexOf(".."!=-1) {
errorStr = "Please enter a valid email address.\n";
alert(errorStr);
highlightField(objEmail);
return false;
}
var illegalChars= /[\(\)\ \{\}\!\%\£\¬\`\'\?\$\^\&\*\|\#\=\+\<\>\,\;\:\\\/\"\[\]]/;
if (strEmail.match(illegalChars)) {
errorStr = "The email address contains illegal characters.\n";
alert(errorStr);
highlightField(objEmail);
return false;
}
return true;
}
Thanks,
ami.
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) == "@" atCount++;
}
var emailFilter=/^.+@.+\..{2,3}$/;
if (!(emailFilter.test(strEmail)) || atCount > 1 || strEmail.indexOf(".."!=-1) {
errorStr = "Please enter a valid email address.\n";
alert(errorStr);
highlightField(objEmail);
return false;
}
var illegalChars= /[\(\)\ \{\}\!\%\£\¬\`\'\?\$\^\&\*\|\#\=\+\<\>\,\;\:\\\/\"\[\]]/;
if (strEmail.match(illegalChars)) {
errorStr = "The email address contains illegal characters.\n";
alert(errorStr);
highlightField(objEmail);
return false;
}
return true;
}
Thanks,
ami.