Email Address Validation using JavaScript

by Dinesh 2014-03-05 17:17:02

<h1>Email Address Validation using JavaScript</h1>A simple JavaScript that validates user input email address is valid or not. If not, the form submition is canceled, and alerts user to re-enter a valid address.

<form name="validation" onSubmit="return checkbae()">
Please input a valid email address:<br />
<input type="text" size=18 name="emailcheck">
<input type="submit" value="Submit">
</form>

<script language="JavaScript1.2">
var testresults
function checkemail(){
var str=document.validation.emailcheck.value
var filter=/^([w-]+(?:.[w-]+)*)@((?:[w-]+.)*w[w-]{0,66}).([a-z]{2,6}(?:.[a-z]{2})?)$/i
if (filter.test(str))
testresults=true
else{
alert("Please input a valid email address!")
testresults=false
}
return (testresults)
}
</script>

<script>
function checkbae(){
if (document.layers||document.getElementById||document.all)
return checkemail()
else
return true
}
</script>



1107
like
0
dislike
0
mail
flag

You must LOGIN to add comments