Thread: Email Validate
View Single Post
  #4 (permalink)  
Old July 3rd, 2003, 11:46 PM
U.N.C.L.E. U.N.C.L.E. is offline
Friend of Wrox
Points: 422, Level: 7
Points: 422, Level: 7 Points: 422, Level: 7 Points: 422, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: La Jolla, CA, USA.
Posts: 112
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is my favorite method: (Caution: won't work if scripting is disabled!)

<html>

<head>
<title>Email Check</title>
</head>

<script language="JavaScript"><!--
function Form_Validator(theForm) {
    var regex = /^[\w\.-]+@[\w\.-]+\.[a-zA-Z]{2,3}$/
    if (!regex.test(theForm.Email.value)) {
        alert("Invalid email address.");
        theForm.Email.focus();
        return (false);
    }
    return (true);
}
//-->
</script>

<body>
  <form method="POST" onsubmit="return Form_Validator(this)" action="javascript:alert('Email is valid')">
    <input name="Email" value="">
    <input type="submit" value="Validate Email">
  </form>
</body>

</html>

Reply With Quote