Aug

25


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

Comments

Name (required)

Email (required)

Website

Speak your mind

1 Comment so far

  1. jakub88 on August 30, 2008 10:47 am

    this totally rocks!

Sponsors




Links