//Function to remove leading and trailing spaces from fields var year; var month; var day; function trim(tmpString){ //Replaces leading spaces while(tmpString.charAt(0) == " "){ tmpString = tmpString.substring(1, tmpString.length); } //Removes trailing spaces while(tmpString.charAt(tmpString.length - 1) == " "){ tmpString = tmpString.substring(0, tmpString.length - 1); } //Returns string return tmpString; } //Function to validate dates function dateChecker(date) { var validDate; validDate = true; //Tests to make sure the string is exactly 10 characters long if (date.length != 10) {validDate = false; return validDate} //Extracts month, day, year, and slashes from string - checks tHDCRegistrationType value for date format sep = "/" month = date.substring(0, 2); firstSlash = date.substring(2, 3); day = date.substring(3, 5); secondSlash = date.substring(5, 6); year = date.substring(6, 10); if (f.tHDCRegistrationType){ if (f.tHDCRegistrationType.value == '2') { //INTL sep = "." month = date.substring(3, 5); firstSlash = date.substring(2, 3); day = date.substring(0, 2); secondSlash = date.substring(5, 6); year = date.substring(6, 10); } } //Test to ensure numeric values if (isNaN(month)) validDate = false; if (isNaN(day)) validDate = false; if (isNaN(year)) validDate = false; //Tests month, day, year, and slashes if (month < 1 | month > 12) validDate = false; if (firstSlash != sep) validDate = false; if (day < 1 | day > 31) validDate = false; if (secondSlash != sep) validDate = false; if (year < 0 | year > 2999) validDate = false; //Checks to make sure that April, June, Sept, or November 31st isn't entered if ((month == 4 | month == 6 | month == 9 | month == 11) & (day == 31)) validDate = false; //Tests February if (month == 2) { var g = parseInt(year/4) if (isNaN(g)) validDate = false; if (day > 29) validDate = false; if (day == 29 & ((year/4) != g)) validDate = false; } //Returns true or false return validDate; } //Function to validate Date of Birth (must be less than today) function dobChecker() { var now = new Date(); var nowYear = now.getFullYear(); var nowMonth = now.getMonth(); var nowDay = now.getDate(); // var dobD = new Date(dob); // var dobYear = dobD.getYear(); // var dobMonth = dobD.getMonth(); // var dobDay = dobD.getDate(); if (year < nowYear){return true} if (year > nowYear){return false} if (month > nowMonth){return false} if (day > nowDay){return false} return true } //Function to remove Twistie image alt values function changeTwistieAlts() { var images = document.images; var imgSource; for (i=0;i-1)||(imgSource.indexOf('collapse.gif'))>-1) { images[i].alt = ''; } } } //The following function are for Phone Number validation function isInteger(s){ var i; for (i = 0; i < s.length; i++){ // Check that current character is number. var c = s.charAt(i); if (((c < "0") || (c > "9"))) return false; } // All characters are numbers. return true; } function stripChars(s, delimiters){ var i; var returnString = ""; // Search through string's characters one by one. // If character is not in delimiters, append to returnString. for (i = 0; i < s.length; i++){ // Check that current character isn't whitespace. var c = s.charAt(i); if (delimiters.indexOf(c) == -1) returnString += c; } return returnString; } function checkPhone(strPhone, international){ var digits = "0123456789"; var phoneNumberDelimiters = "()-. "; var minDigitsInIPhoneNumber = 10; if(international) phoneNumberDelimiters += "+"; s=stripChars(strPhone,phoneNumberDelimiters); return (isInteger(s) && s.length >= minDigitsInIPhoneNumber); }