JavaScript Email validation Using Regular Expression
In this tutorial of Php Point we will show you a simple way of validating email address using javascript and Regular Expression
<html>
<head>
<title>JavaScript form validation Using regular expression</title>
<script type= “text/javascript”>
function Validate(input)
{
var format = /^w+([.-]?w+)*@w+([.-]?w+)*(.w{2,3})+$/;
if(document.getElementById(“email”).value.match(format))
{
document.myform.email.focus();
return true;
}
else
{
alert(“You have entered an wrong email address!”);
document.myform.email.focus();
return false;
}
}
</script>
</head>
<body>
<h2>Input an email and Submit</h2>
<form name=”myform” action=”#”>
<input type=’text’ name=’email’ id=”email”/>
<input type=”submit” name=”submit” value=”Submit” onclick=”Validate(document.myform.email)”/>
</form>
</body>
</html>
Hope this php tutorial is useful for you. Keep following Php Point for more Codes.