Aug
25
JavaScript Validating Email Address
August 25, 2008 |
One blog reader requested a JavaScript validator that validates email address, below is the HTML with JavaScript regular expression code that validates the email address.
<html>
<head>
<title>Validating E-mail Addresses</title>
</head>
<body>
<form name="form1">
<input type="textbox" name="txtInput" />
<script type="text/javascript">
function validate() {
if (! document.form1.txtInput.value.match(/^[\w\d!#$%&'*+-
\/=?^`{|}~]+(\.[\w\d!#$%&'*+-\/=?^`{|}~]+)*@
([a-z\d][-a-z\d]*[a-z\d]\.)*[a-z][-a-z\d]*[a-z]$/)) {
alert("Please enter valid value!")
} else {
alert("Success!")
}
}
</script>
<input type="button" name="btnSubmit" onclick="validate()" value="Go" />
</form>
</body>
</html>
Similar Posts
- None Found
Comments
1 Comment so far



































this totally rocks!