Single E-Mail Address Validation using JavaScript
JavaScript Function:
<script language = "Javascript">
function Validateemail()
{
var emailaddress = document.getElementById('<%=txtEmail.ClientID %>').value;
var isValidEmail = true;
var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
isValidEmail = emailPattern.test(emailaddress);
if (isValidEmail == false)
{
alert("invalide Email Address");
return false;
}
else
{
return true;
}
}
</script>
HTML Form Coding
<form name="frmSample" method="post" action="#" onSubmit="return Validateemail()">
<p>Enter an Email Address :
<input type="text" name="txtEmail">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
Check Functionality Below:
No comments:
Post a Comment