Hi,
I am trying to validate these values, this seems to work fine for the
phone number and name but I am trying to get the program to fail to
submit and set the focus on the date when 2006 is selected and
submitted.
Thanks in advance for any help.
<HTML>
<head>
<link rel="stylesheet" type="text/css" href="test.css"/>
<script language="JavaScript">
<!------------------------------------GENERIC
TEST-------------------------------------------------------------->
function genericTest(anyRE,title,stringToTest) {
if(anyRE.test(stringToTest)) {
return true;
} else {
window.alert("The " + title +" format of:\n" + stringToTest + "\nwas
not recognised.");
return false;
}
}
<!------------------------------------CHECK
WHOLE-------------------------------------------------------------->
function checkWhole() {
/*
if OK variable is false, skip subsequent tests so user can
correct entries one at a time in the same order as on the form
*/
OK = checkFullName(document.form1.CCName.value);
OK = checkDate(document.form1.CCEYear.value);
if ( OK ) OK = genericTest(phoneRE,"telephone
number",document.form1.phone.value);
return OK; // OK false if any ONE (or more) test fails
}
<!------------------------------------CHECK FULL
NAME-------------------------------------------------------------->
// Reject full name if less than 5 characters
function checkFullName (fn) {
if(fn.length < 5) { // reject missing or full name less than 5
characters
window.alert("The full name format:\n" + fn + "\nwas not recognised
(missing or too short).");
return false;
} else {
return true;
}
}
function checkDate(val){
if(val==2006){
window.alert("Invalid Year");
return false;
} else {
return true;
}
}
/*PHONE RE*/
phoneRE = /^(\+|\s)*\d(\d|\s)*(\(\s*\d(\d|\s)*\)|(\d|\s)*)(\d |\s)+(x\s*\d(\d|\s)*|ext\s*\d(\d|\s)*)?$/i;
/*friendly_emailRE*/
friendly_eMailRE = /^\s*[\w\-\.]+@([a-z0-9]+\.){1,3}[a-z]{2,6}\s*$/i;
/*this e-mail address RE is COMPUTER friendly because it rejects all
spaces*/
eMailRE = /^[\w\-\.]+@([a-z0-9]+\.){1,3}[a-z]{2,6}$/i;
</script>
</head>
<BODY>
<IMG SRC="logo.gif"><BR>
<H1>Order Form</H1>
<HR>
<FORM NAME="form1" method="post"
action="https://media.paisley.ac.uk/cgi-davison/shopMail.cgi"
onSubmit="return checkWhole();">
<table border=0 ><tr>
</tr>
<th>Phone</th><th><INPUT TYPE="TEXT" NAME="phone" SIZE=25
onChange='dummy=genericTest(phoneRE,"telephone
number",this.value);'></th>
</tr>
<tr>
<th>
</tr>
<tr>
<th>CCName</th><th><INPUT TYPE="TEXT" NAME="CCName" SIZE=30
onChange='dummy=checkFullName(this.value);'></th>
<tr>
<th>Card ExpiryYear</th>
<th><select name="CCEYear" tabindex="1" ;>
<option value= "invalid" SELECTED > Select Year</option>
<option vale="2005" >2005</option>
<option vale="2006" >2006</option>
<option vale="2007" >2007</option>
<option vale="2008" >2008</option>
</select></th>
</table>
<input type="hidden" name="recipient" value="ab*@hotmail.com">
</SCRIPT>
</TABLE>
<INPUT TYPE="SUBMIT" VALUE="Submit Order">
</FORM>
</BODY>
</HTML>