Phone Number Validation
<html>
<head>
<title>Phone Number Validation</title>
<script language="JavaScript">
<!--
function validatePhone(areaCode,prefix,extension)
{
var phoneNum = new String(areaCode + "-" + prefix + "-" + extension);
var regExpObj = /(\d\d\d)-\d\d\d-\d\d\d\d/;
if(regExpObj.exec(phoneNum) == null)
{
alert(phoneNum + " does not contain a valid code!");
}
else
{
alert("Thank you for your order!");
}
}
// end script-->
</script>
</head>
<body>
<center>
<h1>Phone Number Validation</h1>
<form name="form1">
Phone Number:
<input type="text" size=3 maxlength=3 name="area">-
<input type="text" size=3 maxlength=3 name="prefix">-
<input type="text" size=4 maxlength=4 name="extension">
<br><br>
<input type="button" value="Submit" onClick="validatePhone(area.value, prefix.value, extension.value)">
</form>
</center>
</body>
</html>
Related examples in the same category