// Array which contains all the messages that may be displayed var MESSAGES = new Array(); // Constants representing messages MSG_MISSING_FNAME = 2; MSG_MISSING_LNAME = 3; MSG_MISSING_ADDRESS = 4; MSG_MISSING_CITY = 5; MSG_INVALID_ZIP = 6; MSG_MISSING_PHONE = 7; MSG_MISSING_FIRST_CLASS = 8; MSG_INVALID_EMAIL = 9; MSG_INVALID_CC = 10; MSG_INVALID_CC_NAME = 11; MSG_INVALID_EXPIRY = 12; MSG_UNCHECKED_POLICY = 13; // Msssages themselves, (in array) MESSAGES[MSG_MISSING_FNAME] = "Please enter your first name"; MESSAGES[MSG_MISSING_LNAME] = "Please enter your last name"; MESSAGES[MSG_MISSING_ADDRESS] = "Please enter your street address"; MESSAGES[MSG_MISSING_CITY] = "Please enter your city"; MESSAGES[MSG_INVALID_ZIP] = "You must enter a valid zip code"; MESSAGES[MSG_MISSING_PHONE] = "Please enter your phone number"; MESSAGES[MSG_MISSING_FIRST_CLASS] = "You must specifiy whether or not this is your first class with us"; MESSAGES[MSG_INVALID_EMAIL] = "You must enter a valid email address"; MESSAGES[MSG_INVALID_CC] = "You must enter a valid credit card number"; MESSAGES[MSG_INVALID_CC_NAME] = "Please enter your name as it appears on your credit card"; MESSAGES[MSG_INVALID_EXPIRY] = "You have entered an invalid expiry date"; MESSAGES[MSG_UNCHECKED_POLICY] = "You must agree to the Class Cancellation / No Show Policy"; // ValidateFirst // Validates the fields on the first form, register1.asp function validateFirst(passform) { // Regular expression for valid zip code (5 digits) var zipRegEx = /^\d{5}$/; // Regular expression for email addresses var emailRegEx = /(^[a-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.]*)@([a-z_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i; // Check for empty first name if( passform.fname.value == "" ) { alert(MESSAGES[MSG_MISSING_FNAME]); return false; } // Check for empty last name if( passform.lname.value == "" ) { alert( MESSAGES[MSG_MISSING_LNAME]); return false; } // Check for empty address if( passform.address.value == "" ) { alert(MESSAGES[MSG_MISSING_ADDRESS]); return false; } // Check for empty city if( passform.city.value == "" ) { alert( MESSAGES[MSG_MISSING_CITY]); return false; } // Check zip against regular expression above if( !zipRegEx.test( passform.Zip.value ) ) { alert(MESSAGES[MSG_INVALID_ZIP]); return false; } // Check for empty phone number if( passform.phone.value == "" ) { alert( MESSAGES[MSG_MISSING_PHONE] ); return false; } // Check for selected first class or not if( !passform.newcust[0].checked && !passform.newcust[1].checked ) { alert( MESSAGES[MSG_MISSING_FIRST_CLASS] ); return false; } return true; } // validFirst function validateSecond( passform ) { // Credit card number regular expression // modified to carry 15 for amex, added |15 var ccRegEx = /^\d{15,16}$/; // Date object used to validate expiration var date = new Date(); // Validate credit card name if( passform.custname.value == "" ) { alert( MESSAGES[MSG_INVALID_CC_NAME] ); return false; } // Validate credit card number if( !ccRegEx.test( passform.card.value ) ) { alert( MESSAGES[MSG_INVALID_CC] ); return false; } // Make sure policy box is checked if( !passform.policy.checked ) { alert( MESSAGES[MSG_UNCHECKED_POLICY] ); return false; } // Validate expiry, same year so check months if( passform.expyr.value == date.getFullYear() ) { if( passform.expmo.value < date.getMonth() ) { alert( MESSAGES[MSG_INVALID_EXPIRY] ); return false; } } // Validate expiry, year before now, automatically invalid else if( passform.expyr.value < date.getFullYear() ) { alert( MESSAGES[MSG_INVALID_EXPIRY] ); return false; } return true; }