HTML and CSS Reference
In-Depth Information
EXAMPLE 17.48 ( CONTINUED )
13
if (ok_Phone(myform.user_phone) == false) {
alert( "Invalid phone number");
myform.user_phone.focus();
myform.user_phone.select();
return false;
}
14
return true;
}
</script>
</head>
<body bgcolor="lightgreen"> <font face="arial" size="+1">
<hr />
<h2> Checking Form Input</h2>
<form name="myform"
action="http://localhost/cgi-bin/environ.pl"
method="post"
15
onSubmit="return ok_Form(this);">
<p>
Please enter your email address: <br />
<input type="text" size=40 name="user_email" />
</p><p>
Please enter your phone number: <br />
<input type="text" size=12 name="user_phone" />
</p>
<input type=submit value="Send" />
</form>
</font>
</body>
</html>
EXPLANATION
1
The function to validate an e-mail address is defined. It is called by the ok_Form()
function on line 7.
2
The local variable called regex is assigned a regular expression, explained in Ex-
ample 17.45.
3
The e-mail address entered by the user, eform.user_email.value , is tested against
the regular expression for validity. The regular expression test() method returns
true or false to the ok_Form function, line 7.
4
The function to validate a phone number is defined. It is called by the ok_Phone()
function on line 13.
5
The local variable called regex is assigned regular expression.
6
The phone number entered by the user, eform.user_phform.value , is tested against
the regular expression for validity. The regular expression test() method returns
true or false to the ok_Phone function, line 13.
Search WWH ::




Custom Search