function isTextFieldBlank(strFormName, strTextFieldName, strMessage) { var myTextbox = eval('document.' + strFormName + '.' + strTextFieldName) var strData = eval('myTextbox.value') strData = trim(strData) if (strData == "") { if (strMessage > "") { alert(strMessage) } eval(myTextbox.select()) eval(myTextbox.focus()) return false; } else return true; } function trim(strText) { // this will get rid of leading spaces while (strText.substring(0,1) == ' ') strText = strText.substring(1, strText.length); // this will get rid of trailing spaces while (strText.substring(strText.length-1,strText.length) == ' ') strText = strText.substring(0, strText.length-1); return strText; } function doesTextFieldContain(strFormName, strTextFieldName, strMessage, strAllowableText) { var myTextbox = eval('document.' + strFormName + '.' + strTextFieldName) var strData = eval('myTextbox.value') strData = trim(strData) var allowed = strAllowableText; // define valid characters for (var i=0; i< strData.length; i++) { if (allowed.indexOf(strData.charAt(i)) == -1) { if (!(strMessage=="")) alert(strMessage) eval(myTextbox.select()) eval(myTextbox.focus()) return false; } } return true; } function isTextFieldNumberBetween(strFormName, strTextFieldName, strMessage, intMinValue, intMaxValue, strNumType) { var myTextbox = eval('document.' + strFormName + '.' + strTextFieldName) var strData = eval('myTextbox.value') strData = trim(strData) if (strNumType == 'f') { if (doesTextFieldContain(strFormName, strTextFieldName, strMessage, '1234567890.')) { if ((parseFloat(strData) < parseFloat(intMinValue)) || (parseFloat(strData) > parseFloat(intMaxValue))) { if (!(strMessage=="")) alert(strMessage) eval(myTextbox.select()) eval(myTextbox.focus()) return false; } } else return false; } else if (strNumType == 'i') { if (doesTextFieldContain(strFormName, strTextFieldName, strMessage, '1234567890')) { if ((parseInt(strData) < parseInt(intMinValue)) || (parseInt(strData) > parseInt(intMaxValue))) { if (!(strMessage=="")) alert(strMessage) eval(myTextbox.select()) eval(myTextbox.focus()) return false; } } else return false; } return true; } function areTextFieldsDate(strFormName, intElementID, strMessage) { var myDay = eval('document.' + strFormName + '.Day' + intElementID + '.value'); var myMonth = eval('document.' + strFormName + '.Month' + intElementID + '.value'); var myYear = eval('document.' + strFormName + '.Year' + intElementID + '.value'); if (!isTextFieldBlank(strFormName, 'Day'+intElementID, strMessage)) return false; if (!isTextFieldBlank(strFormName, 'Month'+intElementID, strMessage)) return false; if (!isTextFieldBlank(strFormName, 'Year'+intElementID, strMessage)) return false; if (!doesTextFieldContain(strFormName, 'Day'+intElementID, strMessage, "1234567890")) return false; if (!doesTextFieldContain(strFormName, 'Month'+intElementID, strMessage, "1234567890")) return false; if (!doesTextFieldContain(strFormName, 'Year'+intElementID, strMessage, "1234567890")) return false; if (myDay<=0 || myDay >31) {dateBoxWarning(strFormName, 'Day'+intElementID, strMessage) return false;} if (myMonth<=0 || myMonth >12) {dateBoxWarning(strFormName, 'Month'+intElementID, strMessage) return false;} if (myYear <1000 || myYear>9999) {dateBoxWarning(strFormName, 'Year'+intElementID, strMessage) return false;} if (!checkMonthLength(myMonth,myDay)) {dateBoxWarning(strFormName, 'Month'+intElementID, '') return false;} if (myMonth == 2) if (!checkLeapMonth(myMonth,myDay,myYear)) {dateBoxWarning(strFormName, 'Month'+intElementID, '') return false} return true; } function isDateEntered(strFormName, intElementID) { var myDay = eval('document.' + strFormName + '.Day' + intElementID + '.value'); var myMonth = eval('document.' + strFormName + '.Month' + intElementID + '.value'); var myYear = eval('document.' + strFormName + '.Year' + intElementID + '.value'); if (myDay != '' || myMonth != '' || myYear != '') return true; else return false; } function checkMonthLength(mm,dd) { mm = parseInt(mm) var months = new Array("","January","February","March","April","May","June","July","August","September","October","November","December") if ((mm == 4 || mm == 6 || mm == 9 || mm == 11) && dd > 30) { alert(months[mm] + " has only 30 days.") return false } else if (dd > 31) { alert(months[mm] + " has only 31 days.") return false } return true } function checkLeapMonth(mm,dd,yyyy) { if (yyyy % 4 > 0 && dd > 28) { alert("February of " + yyyy + " has only 28 days.") return false } else if (dd > 29) { alert("February of " + yyyy + " has only 29 days.") return false } return true } function dateBoxWarning(strFormName, strElement, strMessage) { var myTextbox = eval('document.' + strFormName + '.' + strElement) if (strMessage !="") alert(strMessage) eval(myTextbox.select()) eval(myTextbox.focus()) } function dateComparison(strFormName ,intElementID, strCompDay, strCompMonth, strCompYear, strComparison, strMessage) { var myDay = eval('document.' + strFormName + '.Day' + intElementID + '.value'); var myMonth = eval('document.' + strFormName + '.Month' + intElementID + '.value'); var myYear = eval('document.' + strFormName + '.Year' + intElementID + '.value'); var myDayBox = eval('document.' + strFormName + '.Day' + intElementID) var blnResult // Note : Javascript accepts dates from 0-11 not 1-12 var dteBase = new Date(myYear, myMonth-1, myDay) var dteCompare = new Date(strCompYear, strCompMonth-1, strCompDay) if (eval('dteCompare' + strComparison + 'dteBase')) blnResult = true; else blnResult = false; if (blnResult == false) { if (strMessage !="") alert(strMessage) eval(myDayBox.select()) eval(myDayBox.focus()) return false; } else return true; } function dateComparisonDP(strFormName ,intElementID1, intElementID2, strComparison, strMessage) { var myDay1 = eval('document.' + strFormName + '.Day' + intElementID1 + '.value'); var myMonth1 = eval('document.' + strFormName + '.Month' + intElementID1 + '.value'); var myYear1 = eval('document.' + strFormName + '.Year' + intElementID1 + '.value'); var blnResult // Note : Javascript accepts dates from 0-11 not 1-12 var dteBase = new Date(myYear1, myMonth1-1, myDay1) var myDay2 = eval('document.' + strFormName + '.Day' + intElementID2 + '.value'); var myMonth2 = eval('document.' + strFormName + '.Month' + intElementID2 + '.value'); var myYear2 = eval('document.' + strFormName + '.Year' + intElementID2 + '.value'); // Note : Javascript accepts dates from 0-11 not 1-12 var dteCompare = new Date(myYear2, myMonth2-1, myDay2) if (eval('dteBase' + strComparison + 'dteCompare')) blnResult = false; else blnResult = true; if (blnResult == false) { if (strMessage !="") alert(strMessage) return false; } else return true; } function isTextFieldPostcode(strFormName, strTextFieldName, strMessage) { var myTextbox = eval('document.' + strFormName + '.' + strTextFieldName) var strData = eval('myTextbox.value') var size, i; size = strData.length strData = strData.toUpperCase(); //Change to uppercase // ensure no non-number/alpha characters (except space) for(i=0;i "9") && (strData.charAt(i) < "A" || strData.charAt(i) > "Z")) { ShowMessageAndSetFocus(myTextbox, strMessage) return false; } } } while (strData.slice(0,1) == " ") //Strip leading spaces {strData = strData.substr(1,size-1);size = strData.length } while(strData.slice(size-1,size)== " ") //Strip trailing spaces {strData = strData.substr(0,size-1);size = strData.length } if (size < 6 || size > 8){ //Code length rule ShowMessageAndSetFocus(myTextbox, strMessage) return false; } if (strData.charAt(0) < "A" || strData.charAt(0) > "Z"){ //leftmost character must be alpha character rule ShowMessageAndSetFocus(myTextbox, strMessage) return false; } if (strData.charAt(size-3) < "0" || strData.charAt(size-3) > "9"){ //first character of inward code must be numeric rule ShowMessageAndSetFocus(myTextbox, strMessage) return false; } if (strData.charAt(size-2) < "A" || strData.charAt(size-2) > "Z"){ //second character of inward code must be alpha rule ShowMessageAndSetFocus(myTextbox, strMessage) return false; } if (strData.charAt(size-1) < "A" || strData.charAt(size-1) > "Z"){ //third character of inward code must be alpha rule ShowMessageAndSetFocus(myTextbox, strMessage) return false; } if (!(strData.charAt(size-4) == " ")){//space in position length-3 rule ShowMessageAndSetFocus(myTextbox, strMessage) return false; } count1 = strData.indexOf(" ");count2 = strData.lastIndexOf(" "); if (count1 != count2){//only one space rule ShowMessageAndSetFocus(myTextbox, strMessage) return false; } return true; } function ShowMessageAndSetFocus(objTextbox, sMessage) { objTextbox.select() objTextbox.focus() alert(sMessage) } function isTextFieldEmail(strFormName, strTextFieldName, strMessage) { var myTextbox = eval('document.' + strFormName + '.' + strTextFieldName) var strData = eval('myTextbox.value') strData = trim(strData) if (strData.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) return true; else { ShowMessageAndSetFocus(myTextbox, strMessage) return false; } }