HTML and CSS Reference
In-Depth Information
Step 6:
[a-zA-Z]{2,4}
The domain name follows the mail server's name. A single
dot separates the server from the domain. The domain
name consists of between two and four alphabetic charac-
ters; for example, savageman@imefdm.usmc.mil or patri-
cia.person@sweden.sun.com.
Step 7:
$
The end of the line anchor assures that no extra char-
acters can be added onto the end of the e-mail address.
Example 17.45 uses a regular expression to check for a valid e-mail address.
EXAMPLE 17.45
<html>
<head><title>Validating E-Mail Addresses</title>
<script type="text/javascript">
1 function ok_Email(eform) {
2 var regex = /^(([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-
\.]+)\.([a-zA-Z]{2,5}){1,25})+([;.](([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-
\.]+)\.([a-zA-Z]{2,5}){1,25})+)*$/;
# this got the highest rating at regexlib.com!!
3
if(regex.test(eform.user_email.value)){
4
return true;
}
else{
5
alert("Enter a valid email address");
return false;
}
}
</script>
</head>
<body>
<hr />
<h2> Checking for Valid Email Address </h2>
6
<form name="formtest"
7
action="http://localhost/cgi-bin/environ.pl"
method="post"
8
onSubmit="return ok_Email(this);">
<p>
Please enter your email address: <br />
<input type="text" size=40 name="user_email" />
</p><p>
<input type=submit value="Send" />
</p>
</form>
</body>
</html>
Search WWH ::




Custom Search