Monday 1 April 2013

Email Validation with JavaScript and Regular Exression

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
function checkEmail(myForm) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.email.value)){
openwin();
return (true)
}
else
alert("Invalid E-mail Address! Please re-enter.");
return (false)
}

function openwin()
{
var e   = document.getElementById('email').value;
myWindow=window.open('','','');
myWindow.document.write("<b>Welcome User!<br/>Your Details are:<br/></b>");
myWindow.document.write("Email: "+e);
}
</script>

</HEAD>
<BODY>
<form onSubmit="return checkEmail(this)">
E-mail Address:<br>
<input type="text" id="email">
<p>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
</body>
</html>

No comments:

Post a Comment