//*******************************************// //* js for common validate *// //*******************************************// //add by jianfeng -- get first check box of the current row function trParent(element){ var parent = element.parentNode; var count = 3; for(var i=0;i= min && str.length <= max) { return 0; } else if (str.length > max) { return 2; } else if (str.length < min) { return 3; } } function isAllDigits(argvalue) { argvalue = argvalue.toString(); var validChars = "0123456789"; var startFrom = 0; if (argvalue.substring(0, 2) == "0x") { validChars = "0123456789abcdefABCDEF"; startFrom = 2; // } else if (argvalue.charAt(0) == "0") { // validChars = "01234567"; // startFrom = 1; } else if (argvalue.charAt(0) == "-") { startFrom = 1; } for(var n = startFrom; n < argvalue.length; n++) { if(validChars.indexOf(argvalue.substring(n, n+1)) == -1) return false; } return true; } function isValidDate(day, month, year) { if (month < 1 || month > 12) { return false; } if (day < 1 || day > 31) { return false; } if ((month == 4 || month == 6 || month == 9 || month == 11) && (day == 31)) { return false; } if (month == 2) { var leap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); if (day>29 || (day == 29 && !leap)) { return false; } } return true; } function validDate(value, datePattern) { var MONTH = "MM"; var DAY = "dd"; var YEAR = "yyyy"; var orderMonth = datePattern.indexOf(MONTH); var orderDay = datePattern.indexOf(DAY); var orderYear = datePattern.indexOf(YEAR); var matched = null; if ((orderDay < orderYear && orderDay > orderMonth)) { var iDelim1 = orderMonth + MONTH.length; var iDelim2 = orderDay + DAY.length; var delim1 = datePattern.substring(iDelim1, iDelim1 + 1); var delim2 = datePattern.substring(iDelim2, iDelim2 + 1); if (iDelim1 == orderDay && iDelim2 == orderYear) { dateRegexp = new RegExp("^(\\d{1,2})(\\d{1,2})(\\d{4})$"); } else if (iDelim1 == orderDay) { dateRegexp = new RegExp("^(\\d{1,2})(\\d{1,2})[" + delim2 + "](\\d{4})$"); } else if (iDelim2 == orderYear) { dateRegexp = new RegExp("^(\\d{1,2})[" + delim1 + "](\\d{1,2})(\\d{4})$"); } else { dateRegexp = new RegExp("^(\\d{1,2})[" + delim1 + "](\\d{1,2})[" + delim2 + "](\\d{4})$"); dateRegexp1 = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$"); } matched = dateRegexp.exec(value); if(matched == null) { matched = dateRegexp1.exec(value); } if(matched != null) { if (!isValidDate(matched[2], matched[1], matched[3])) { matched = null; } } } else if ((orderMonth < orderYear && orderMonth > orderDay)) { var iDelim1 = orderDay + DAY.length; var iDelim2 = orderMonth + MONTH.length; var delim1 = datePattern.substring(iDelim1, iDelim1 + 1); var delim2 = datePattern.substring(iDelim2, iDelim2 + 1); if (iDelim1 == orderMonth && iDelim2 == orderYear) { dateRegexp = new RegExp("^(\\d{1,2})(\\d{1,2})(\\d{4})$"); } else if (iDelim1 == orderMonth) { dateRegexp = new RegExp("^(\\d{1,2})(\\d{1,2})[" + delim2 + "](\\d{4})$"); } else if (iDelim2 == orderYear) { dateRegexp = new RegExp("^(\\d{1,2})[" + delim1 + "](\\d{1,2})(\\d{4})$"); } else { dateRegexp = new RegExp("^(\\d{1,2})[" + delim1 + "](\\d{1,2})[" + delim2 + "](\\d{4})$"); dateRegexp1 = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$"); } matched = dateRegexp.exec(value); if(matched == null) { matched = dateRegexp1.exec(value); } if(matched != null) { if (!isValidDate(matched[1], matched[2], matched[3])) { matched = null; } } } else if ((orderMonth > orderYear && orderMonth < orderDay)) { var iDelim1 = orderYear + YEAR.length; var iDelim2 = orderMonth + MONTH.length; var delim1 = datePattern.substring(iDelim1, iDelim1 + 1); var delim2 = datePattern.substring(iDelim2, iDelim2 + 1); if (iDelim1 == orderMonth && iDelim2 == orderDay) { dateRegexp = new RegExp("^(\\d{4})(\\d{1,2})(\\d{1,2})$"); } else if (iDelim1 == orderMonth) { dateRegexp = new RegExp("^(\\d{4})(\\d{1,2})[" + delim2 + "](\\d{1,2})$"); } else if (iDelim2 == orderDay) { dateRegexp = new RegExp("^(\\d{4})[" + delim1 + "](\\d{1,2})(\\d{1,2})$"); } else { dateRegexp = new RegExp("^(\\d{4})[" + delim1 + "](\\d{1,2})[" + delim2 + "](\\d{1,2})$"); dateRegexp1 = new RegExp("^(\\d{4})(\\d{2})(\\d{2})$"); } matched = dateRegexp.exec(value); if(matched == null) { matched = dateRegexp1.exec(value); } if(matched != null) { if(!isValidDate(matched[3], matched[2], matched[1])) { matched = null; } } } else { matched = null; } return matched; } function isValidDate(day, month, year) { if (month < 1 || month > 12) { return false; } if (day < 1 || day > 31) { return false; } if ((month == 4 || month == 6 || month == 9 || month == 11) &&(day == 31)) { return false; } if(month == 2) { var leap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); if (day>29 || (day == 29 && !leap)) { return false; } } return true; } function dateFormat(date, datePattern) { var MONTH = "MM"; var DAY = "dd"; var YEAR = "yyyy"; var _date, _month, _year, displayDate = datePattern; _date = date.getDate() <= 8 ? "0"+date.getDate() : date.getDate(); _month = date.getMonth() <=8 ? "0"+(date.getMonth()+1) : date.getMonth()+1; _year = date.getFullYear(); displayDate = displayDate.replace(DAY, _date); displayDate = displayDate.replace(MONTH, _month); displayDate = displayDate.replace(YEAR, _year); return displayDate; } function validateRequired(form, paramsFunctionName) { var isValid = true; var focusField = null; var i = 0; var fields = new Array(); var formName = form.getAttributeNode("name"); oRequired = eval('new ' + paramsFunctionName + '_RequiredValidations()'); for (x in oRequired) { var field = form[oRequired[x][0]]; var deleteIndicator = oRequired[x][1]; var checkBoxValue = isCheck(field); if((checkBoxValue == false && deleteIndicator == "true" ) || deleteIndicator == "false") { if((field.type == 'text' || field.type == 'textarea' || field.type == 'file' || field.type == 'select-one' || field.type == 'radio' || field.type == 'password'|| field.type == 'hidden' || field.type == 'select-multiple') && field.disabled == false ){ var value = ''; if(field.type == "select-one") { var si = field.selectedIndex; if(si >= 0) { value = field.options[si].value; } } else if(field.type == 'select-multiple') { var si = field.options.length; if(si > 0) { value = new String(field.options.length) ; } } else { value = field.value; } if(trim(value).length == 0) { if((focusField == null)&&(field.type != 'hidden')) { focusField = field; } if(field.type == 'select-one' || field.type == 'select-multiple') { // fields[i++] = oRequired[x][1].replace("enter","select"); fields[i]= new Array(); fields[i][0] = oRequired[x][0]; fields[i][1] = oRequired[x][2].replace("enter","select"); i++; } else { // fields[i++] = oRequired[x][1]; fields[i]= new Array(); fields[i][0] = oRequired[x][0]; fields[i][1] = oRequired[x][2]; i++; } isValid = false; } } } } if(fields.length > 0) { isValid = false; if(focusField != null) { focusField.focus(); } // alert(fields.join('\n')); displayValidateMessage(fields); } return isValid; } function validateMinLength(form, paramsFunctionName) { var isValid = true; var focusField = null; var i = 0; var fields = new Array(); var formName = form.getAttributeNode("name"); oMinLength = eval('new ' + paramsFunctionName + '_MinlengthValidations()'); for (x in oMinLength) { var field = form[oMinLength[x][0]]; var deleteIndicator = oMinLength[x][1]; var checkBoxValue = isCheck(field); if((checkBoxValue == false && deleteIndicator == "true" ) || deleteIndicator == "false") { if ((field.type == 'hidden' || field.type == 'text' || field.type == 'password' || field.type == 'textarea') && field.disabled == false) { var value = trim(field.value); if(value.length != 0) { var iMin = parseInt(oMinLength[x][3]("minlength")); if ((value.length > 0) && (value.length < iMin)) { if((focusField == null)&&(field.type != 'hidden')) { focusField = field; } // fields[i++] = oMinLength[x][1]; fields[i]=new Array(); fields[i][0] = oMinLength[x][0]; fields[i][1] = oMinLength[x][2]; i++; isValid = false; } } } } } if (fields.length > 0) { isValid=false; if(focusField != null) { focusField.focus(); } // alert(fields.join('\n')); displayValidateMessage(fields); } return isValid; } function validateMaxLength(form, paramsFunctionName) { var isValid = true; var focusField = null; var i = 0; var fields = new Array(); var formName = form.getAttributeNode("name"); oMaxLength = eval('new ' + paramsFunctionName + '_MaxlengthValidations()'); for (x in oMaxLength) { var field = form[oMaxLength[x][0]]; var deleteIndicator = oMaxLength[x][1]; var checkBoxValue = isCheck(field); if((checkBoxValue == false && deleteIndicator == "true" ) || deleteIndicator == "false") { if ((field.type == 'hidden' || field.type == 'text' || field.type == 'password' || field.type == 'textarea') && field.disabled == false) { var iMax = parseInt(oMaxLength[x][3]("maxlength")); var value = trim(field.value); if(value.length != 0) { if (value.length > iMax) { if((focusField == null)&&(field.type != 'hidden')) { focusField = field; } // fields[i++] = oMaxLength[x][1]; fields[i]=new Array(); fields[i][0] = oMaxLength[x][0]; fields[i][1] = oMaxLength[x][2]; i++; isValid = false; } } } } } if (fields.length > 0) { isValid=false; if(focusField != null) { focusField.focus(); } // alert(fields.join('\n')); displayValidateMessage(fields); } return isValid; } function validateMask(form, paramsFunctionName) { var isValid = true; var focusField = null; var i = 0; var fields = new Array(); var formName = form.getAttributeNode("name"); oMasked = eval('new ' + paramsFunctionName + '_MaskValidations()'); for (x in oMasked) { var field = form[oMasked[x][0]]; var deleteIndicator = oMasked[x][1]; var checkBoxValue = isCheck(field); if((checkBoxValue == false && deleteIndicator == "true" ) || deleteIndicator == "false") { if ((field.type == 'hidden' || field.type == 'text' || field.type == 'textarea' || field.type == 'file') && (field.value.length > 0) && field.disabled == false) { var xp =oMasked[x][3]("mask"); var value = trim(field.value); if(value.length != 0) { // xp = xp.replace (/\\/g,"\\"); if (!matchPattern(value, xp)) { if((focusField == null)&&(field.type != 'hidden')) { focusField = field; } // fields[i++] = oMasked[x][1]; fields[i]=new Array(); fields[i][0] = oMasked[x][0]; fields[i][1] = oMasked[x][2]; i++; isValid = false; } } } } } if (fields.length > 0) { isValid=false; if(focusField != null) { focusField.focus(); } // alert(fields.join('\n')); displayValidateMessage(fields); } return isValid; } function validateEmail(form, paramsFunctionName) { // add by yuanbin var isValid = true; var focusField = null; var i = 0; var fields = new Array(); var formName = form.getAttributeNode("name"); oEmailed = eval('new ' + paramsFunctionName + '_EmailValidations()'); for (x in oEmailed) { var field = form[oEmailed[x][0]]; var deleteIndicator = oEmailed[x][1]; var checkBoxValue = isCheck(field); if((checkBoxValue == false && deleteIndicator == "true" ) || deleteIndicator == "false") { if ((field.type == 'hidden' || field.type == 'text' || field.type == 'textarea') && (field.value.length > 0) && field.disabled == false) { if(!commonValidateEmail(field.value)) { if((focusField == null) && (field.type != 'hidden')) { focusField = field; } fields[i]=new Array(); fields[i][0] = oEmailed[x][0]; fields[i][1] = oEmailed[x][2]; i++; isValid = false; } } } } if (fields.length > 0) { isValid=false; if(focusField != null) { focusField.focus(); } // alert(fields.join('\n')); displayValidateMessage(fields); } return isValid; } function commonValidateEmail(str) { var value = trim(str); if(value.length != 0) { isEmail = new RegExp(/^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/i); result1 = isEmail.test(value); //Email Local Part – X(64) Email Sign – X(1) Email Domain – X(255) emaildomain = new RegExp(/^(.{1,64})@(.{1,255})$/); result2 = emaildomain.test(value); return result1 && result2; } return true; } function validateWebsiteURL(form, paramsFunctionName) { // add by yuanbin var isValid = true; var focusField = null; var i = 0; var fields = new Array(); var formName = form.getAttributeNode("name"); webSite = eval('new ' + paramsFunctionName + '_WebsiteURLValidations()'); for (x in webSite) { var field = form[webSite[x][0]]; var deleteIndicator = webSite[x][1]; var checkBoxValue = isCheck(field); if((checkBoxValue == false && deleteIndicator == "true" ) || deleteIndicator == "false") { if ((field.type == 'hidden' || field.type == 'text' || field.type == 'textarea') && (field.value.length > 0) && field.disabled == false) { var value = trim(field.value); if(value.length != 0) { isWebsiteURL = new RegExp(/^(https|http):\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^\"\"])*$/); result = isWebsiteURL.test(value); if(result == false) { if((focusField == null)&&(field.type != 'hidden')) { focusField = field; } fields[i]=new Array(); fields[i][0] = webSite[x][0]; fields[i][1] = webSite[x][2]; i++; isValid = false; } } } } } if (fields.length > 0) { isValid=false; if(focusField != null) { focusField.focus(); } // alert(fields.join('\n')); displayValidateMessage(fields); } return isValid; } function validateUenNumber(form, paramsFunctionName) { var isValid = true; var focusField = null; var i = 0; var fields = new Array(); var formName = form.getAttributeNode("name"); uen = eval('new ' + paramsFunctionName + '_uenValidations()'); for (x in uen) { var field = form[uen[x][0]]; var deleteIndicator = uen[x][1]; var checkBoxValue = isCheck(field); if((checkBoxValue == false && deleteIndicator == "true" ) || deleteIndicator == "false") { if ((field.type == 'hidden' || field.type == 'text' || field.type == 'textarea') && (field.value.length > 0) && field.disabled == false) { var value = trim(field.value); if(value.length != 0) { isUen = new RegExp(/^([0-9]{4}|(F|f)\s{3})[0-9]{5}[A-Za-z]{1}$/); result = isUen.test(value); if(result == false) { if((focusField == null)&&(field.type != 'hidden')) { focusField = field; } fields[i]=new Array(); fields[i][0] = uen[x][0]; fields[i][1] = uen[x][2]; i++; isValid = false; } } } } } if (fields.length > 0) { isValid=false; if(focusField != null) { focusField.focus(); } // alert(fields.join('\n')); displayValidateMessage(fields); } return isValid; } function validateInteger(form, paramsFunctionName) { var isValid = true; var focusField = null; var i = 0; var fields = new Array(); var formName = form.getAttributeNode("name"); oInteger = eval('new ' + paramsFunctionName + '_IntegerValidations()'); for (x in oInteger) { var field = form[oInteger[x][0]]; var deleteIndicator = oInteger[x][1]; var checkBoxValue = isCheck(field); if((checkBoxValue == false && deleteIndicator == "true" ) || deleteIndicator == "false") { if ((field.type == 'hidden' || field.type == 'text' || field.type == 'textarea' || field.type == 'select-one' || field.type == 'radio') && field.disabled == false) { var value = ''; if (field.type == "select-one") { var si = field.selectedIndex; if (si >= 0) { value = field.options[si].value; } } else { value = field.value; } value=trim(value); if(value.length > 0) { if (!isAllDigits(value)) { isValid = false; if((focusField == null)&&(field.type != 'hidden')) { focusField = field; } // fields[i++] = oInteger[x][1]; fields[i]=new Array(); fields[i][0] = oInteger[x][0]; fields[i][1] = oInteger[x][2]; i++; } else { var iValue = parseInt(value); if(isNaN(iValue) || !(iValue >= -2147483648 && iValue <= 2147483647)) { if((focusField == null)&&(field.type != 'hidden')) { focusField = field; } // fields[i++] = oInteger[x][1]; fields[i]=new Array(); fields[i][0] = oInteger[x][0]; fields[i][1] = oInteger[x][2]; i++; isValid = false; } } } } } } if (fields.length > 0) { isValid=false; if(focusField != null) { focusField.focus(); } displayValidateMessage(fields); // alert(fields.join('\n')); } return isValid; } function validateIntRange(form, paramsFunctionName) { var isValid = true; var focusField = null; var i = 0; var fields = new Array(); var formName = form.getAttributeNode("name"); oRange = eval('new ' + paramsFunctionName + '_IntegerRangeValidations()'); for (x in oRange) { var field = form[oRange[x][0]]; var deleteIndicator = oRange[x][1]; var checkBoxValue = isCheck(field); if((checkBoxValue == false && deleteIndicator == "true" ) || deleteIndicator == "false") { if (field.disabled == false) { if ((field.type == 'text' || field.type == 'textarea') && (field.value.length > 0)) { var value = trim(field.value); if(value.length != 0) { var iMin = (oRange[x][3]("min")); var iMax = (oRange[x][3]("max")); var iValue = parseInt(value); if (!(iValue >= iMin && iValue <= iMax)) { if((focusField == null)&&(field.type != 'hidden')) { focusField = field; } // fields[i++] = oRange[x][1]; fields[i]= new Array(); fields[i][0] = oRange[x][0]; fields[i][1] = oRange[x][2]; i++; isValid = false; } } } } } } if (fields.length > 0) { isValid=false; if(focusField != null) { focusField.focus(); } displayValidateMessage(fields); // alert(fields.join('\n')); } return isValid; } function validateFloat(form, paramsFunctionName) { var isValid = true; var focusField = null; var i = 0; var fields = new Array(); var formName = form.getAttributeNode("name"); oFloat = eval('new ' + paramsFunctionName + '_FloatValidations()'); for (x in oFloat) { var field = form[oFloat[x][0]]; var deleteIndicator = oFloat[x][1]; var checkBoxValue = isCheck(field); if((checkBoxValue == false && deleteIndicator == "true" ) || deleteIndicator == "false") { if ((field.type == 'hidden' || field.type == 'text' || field.type == 'textarea' || field.type == 'select-one' || field.type == 'radio') && field.disabled == false) { var value = ''; if(field.type == "select-one") { var si = field.selectedIndex; if (si >= 0) { value = field.options[si].value; } } else { value = field.value; } value = trim(value); if(value.length > 0) { var tempArray = value.split('.'); var joinedString= tempArray.join(''); if(!isAllDigits(joinedString)) { isValid = false; if((focusField == null)&&(field.type != 'hidden')) { focusField = field; } // fields[i++] = oFloat[x][1]; fields[i]= new Array(); fields[i][0] = oFloat[x][0]; fields[i][1] = oFloat[x][2]; i++; } else { var iValue = parseFloat(value); if(isNaN(iValue)) { if((focusField == null)&&(field.type != 'hidden')) { focusField = field; } // fields[i++] = oFloat[x][1]; fields[i]= new Array(); fields[i][0] = oFloat[x][0]; fields[i][1] = oFloat[x][2]; i++; isValid = false; } } } } } } if (fields.length > 0) { isValid=false; if(focusField != null) { focusField.focus(); } // alert(fields.join('\n')); displayValidateMessage(fields); } return isValid; } function validateFloatRange(form, paramsFunctionName) { var isValid = true; var focusField = null; var i = 0; var fields = new Array(); var formName = form.getAttributeNode("name"); oRange = eval('new ' + paramsFunctionName + '_FloatRangeValidations()'); for (x in oRange){ var field = form[oRange[x][0]]; var deleteIndicator = oRange[x][1]; var checkBoxValue = isCheck(field); if((checkBoxValue == false && deleteIndicator == "true" ) || deleteIndicator == "false") { if (field.disabled == false) { if ((field.type == 'text' || field.type == 'textarea') && (field.value.length > 0)) { var fMin = (oRange[x][3]("min")); var fMax = (oRange[x][3]("max")); var value = trim(field.value); if(value.length != 0) { var fValue = parseFloat(value); if(!(fValue >= fMin && fValue <= fMax)) { if((focusField == null)&&(field.type != 'hidden')) { focusField = field; } // fields[i++] = oRange[x][1]; fields[i]= new Array(); fields[i][0] = oRange[x][0]; fields[i][1] = oRange[x][2]; i++; isValid = false; } } } } } } if (fields.length > 0) { isValid=false; if(focusField != null) { focusField.focus(); } // alert(fields.join('\n')); displayValidateMessage(fields); } return isValid; } function validateMoney(form, paramsFunctionName) { var result = true; var isValid = true; var i = 0; var fields = new Array(); var focusField = null; var formName = form.getAttributeNode("name"); oMoney = eval('new ' + paramsFunctionName + '_MoneyValidations()'); for (x in oMoney) { var field = form[oMoney[x][0]]; var deleteIndicator = oMoney[x][1]; var checkBoxValue = isCheck(field); if((checkBoxValue == false && deleteIndicator == "true" ) || deleteIndicator == "false") { if (field.disabled == false) { var value = field.value; value = trim(value); if(value.length != 0) { // isMoney = new // RegExp(/^(\-?|\+?)((\d{1,3}((,\d{3})*))|(\d+))((\.\d+){0,1})$/); isMoney = new RegExp(/^(\-?|\+?)((\d{1,3}((,\d{3})*))|(\d+))((\.\d{1,2}){0,1})$/); // isMoney = new // RegExp(/^[0-9]{1,3}(,[0-9]{3})*(.[0-9]{1,2})?$/); result = isMoney.test(value); if(result == false) { if((focusField == null)&&(field.type != 'hidden')) { focusField = field; } // fields[i++] = oMoney[x][1]; fields[i]= new Array(); fields[i][0] = oMoney[x][0]; fields[i][1] = oMoney[x][2]; i++; isValid = false; } } } } } if (fields.length > 0) { isValid=false; if(focusField != null) { focusField.focus(); } // alert(fields.join('\n')); displayValidateMessage(fields); } return result; } function validateForbidSpace(form, paramsFunctionName) { var isValid = true; var focusField = null; var i = 0; var fields = new Array(); var formName = form.getAttributeNode("name"); oRequired = eval('new ' + paramsFunctionName + '_ForbidSpaceValidations()'); for (x in oRequired) { var field = form[oRequired[x][0]]; var deleteIndicator = oRequired[x][1]; var checkBoxValue = isCheck(field); if((checkBoxValue == false && deleteIndicator == "true" ) || deleteIndicator == "false") { if((field.type == 'text' || field.type == 'textarea' || field.type == 'password'|| field.type == 'hidden') && field.disabled == false) { value = trim(field.value); if(value.length == 0) { continue; } if(value.indexOf(" ") >= 0) { if((focusField == null)&&(field.type != 'hidden')) { focusField = field; } // fields[i++] = oRequired[x][1]; fields[i]= new Array(); fields[i][0] = oRequired[x][0]; fields[i][1] = oRequired[x][2]; i++; isValid = false; } } } } if(fields.length > 0) { isValid = false; if(focusField != null) { focusField.focus(); } // alert(fields.join('\n')); displayValidateMessage(fields); } return isValid; } function validateNotEmpty(form, paramsFunctionName) { var isValid = true; var focusField = null; var i = 0; var fields = new Array(); var formName = form.getAttributeNode("name"); oRequired = eval('new ' + paramsFunctionName + '_NotEmptyValidations()'); for (x in oRequired) { var field = form[oRequired[x][0]]; var deleteIndicator = oRequired[x][1]; var checkBoxValue = isCheck(field); if((checkBoxValue == false && deleteIndicator == "true" ) || deleteIndicator == "false") { if(field.type == 'select-multiple' && field.disabled == false) { if(field.options.length <= 0) { if(focusField == null) { focusField = field; } // fields[i++] = oRequired[x][1]; fields[i]= new Array(); fields[i][0] = oRequired[x][0]; fields[i][1] = oRequired[x][2]; i++; isValid = false; } } } } if(fields.length > 0) { isValid = false; if(focusField != null) { focusField.focus(); } // alert(fields.join('\n')); displayValidateMessage(fields); } return isValid; } function validateNumeric(form, paramsFunctionName) { var isValid = true; var focusField = null; var i = 0; var fields = new Array(); var formName = form.getAttributeNode("name"); oRequired = eval('new ' + paramsFunctionName + '_NumericValidations()'); for (x in oRequired) { var field = form[oRequired[x][0]]; var deleteIndicator = oRequired[x][1]; var checkBoxValue = isCheck(field); if((checkBoxValue == false && deleteIndicator == "true" ) || deleteIndicator == "false") { if((field.type == 'text' || field.type == 'textarea' || field.type == 'password'|| field.type == 'hidden')&& field.disabled == false) { value = trim(field.value); if(value.length == 0) { continue; } for(var j = 0; j < value.length; ++j) { if((value.charAt(j) <'0')||(field.value.charAt(j) > '9')) { if((field != null)&&(field.type != 'hidden')) { focusField = field; } // fields[i++] = oRequired[x][1]; fields[i]= new Array(); fields[i][0] = oRequired[x][0]; fields[i][1] = oRequired[x][2]; i++; isValid = false; break; } } } } } if(fields.length > 0) { isValid = false; if(focusField != null) { focusField.focus(); } // alert(fields.join('\n')); displayValidateMessage(fields); } return isValid; } function validateAlphaNumeric(form, paramsFunctionName) { var isValid = true; var focusField = null; var i = 0; var fields = new Array(); var formName = form.getAttributeNode("name"); oRequired = eval('new ' + paramsFunctionName + '_AlphaNumericValidations()'); for (x in oRequired) { var field = form[oRequired[x][0]]; var deleteIndicator = oRequired[x][1]; var checkBoxValue = isCheck(field); if((checkBoxValue == false && deleteIndicator == "true" ) || deleteIndicator == "false") { if((field.type == 'text' || field.type == 'textarea' || field.type == 'password'|| field.type == 'hidden') && field.disabled == false) { value = trim(field.value); if(value.length == 0) { continue; } for(var j = 0; j < value.length; ++j) { if(((value.charAt(j) <'0')||(field.value.charAt(j) > '9'))&& ((value.charAt(j) <'A')||(field.value.charAt(j) > 'Z'))&& ((value.charAt(j) <'a')||(field.value.charAt(j) > 'z'))) { if((focusField == null)&&(field.type != 'hidden')) { focusField = field; } // fields[i++] = oRequired[x][1]; fields[i]= new Array(); fields[i][0] = oRequired[x][0]; fields[i][1] = oRequired[x][2]; i++; isValid = false; break; } } } } } if(fields.length > 0) { isValid = false; if(focusField != null) { focusField.focus(); } // alert(fields.join('\n')); displayValidateMessage(fields); } return isValid; } function validateNosign(form, paramsFunctionName) { var isValid = true; var i = 0; var fields = new Array(); var focusField = null; var formName = form.getAttributeNode("name"); oNosign = eval('new ' + paramsFunctionName + '_NosignValidations()'); for (x in oNosign) { var field = form[oNosign[x][0]]; var value = field.value; value = trim(value); var deleteIndicator = oNosign[x][1]; var checkBoxValue = isCheck(field); if((checkBoxValue == false && deleteIndicator == "true" ) || deleteIndicator == "false") { if(value.length != 0) { if((value.charAt(0) == '+')||( value.charAt(0) == '-')) { if((focusField == null)&&(field.type != 'hidden')) { focusField = field; } // fields[i++] = oNosign[x][1]; fields[i]= new Array(); fields[i][0] = oNosign[x][0]; fields[i][1] = oNosign[x][2]; i++; isValid = false; } } } } if (fields.length > 0) { isValid=false; if(focusField != null) { focusField.focus(); } // alert(fields.join('\n')); displayValidateMessage(fields); } return isValid; } function validateAllowNullMoney(form, paramsFunctionName) { return true; } function validateSingaporeNRICNumber(form, paramsFunctionName) { var isValid = true; var focusField = null; var i = 0; var fields = new Array(); var formName = form.getAttributeNode("name"); oSGNricNumber = eval('new ' + paramsFunctionName + '_sgNricValidations()'); for (x in oSGNricNumber) { isValid = true; var field = form[oSGNricNumber[x][0]]; var deleteIndicator = oSGNricNumber[x][1]; var checkBoxValue = isCheck(field); if((checkBoxValue == false && deleteIndicator == "true" ) || deleteIndicator == "false") { if((field.type == 'text' || field.type == 'textarea' || field.type == 'hidden') && field.disabled == false ){ var value = field.value; if(trim(value).length != 0) { var result = isValidUINFIN(trim(value)); if(result !=0) { // invalidate NRIC number fields[i]= new Array(); fields[i][0] = oSGNricNumber[x][0]; fields[i][1] = oSGNricNumber[x][2]; i++; isValid = false; if((focusField == null)&&(field.type != 'hidden')) { focusField = field; } } } } } } if(fields.length > 0) { isValid = false; if(focusField != null) { focusField.focus(); } // alert(fields.join('\n')); displayValidateMessage(fields); } return isValid; } function validatePrecision(form, paramsFunctionName) { var isValid = true; var focusField = null; var fields = new Array(); var formName = form.getAttributeNode("name"); oMasked = eval('new ' + paramsFunctionName + '_PrecisionValidations()'); var z = 0; for (x in oMasked) { var field = form[oMasked[x][0]]; var value = trim(field.value); if(value.length == 0) { continue; } var deleteIndicator = oMasked[x][1]; var checkBoxValue = isCheck(field); if((checkBoxValue == false && deleteIndicator == "true" ) || deleteIndicator == "false") { if ((field.type == 'text' || field.type == 'textarea') && (value.length > 0) && field.disabled == false) { var precs =oMasked[x][3]("precision"); var a = precs.split(","); var intcount0 = 0; var intcount1 = 0; var intcount2 = 0; if(precs != null) { var first = false; var second = false; for(var i = 0; i < value.length; ++i) { if((value.charAt(i) >='0')&&(value.charAt(i) <= '9')) { ++intcount0; } else { if(value.charAt(i) =='.') { if((intcount2 != 0)||(i == value.length - 1)) { var index = oMasked[x][1].indexOf("|"); if(index < 0) { fields[z] = oMasked[x][1]; } else { var tMsg = oMasked[x][1].substring(0, index); fields[z] = tMsg.replace("##", a[1]); } isValid = false; first = true; if(z == 0) { focusField = field; } ++z; break; } intcount2 = intcount0; } else if(!((i == 0)&&((value.charAt(i) == '-')||(value.charAt(i) == '+')))) { var index = oMasked[x][1].indexOf("|"); if(index < 0) { // fields[z] = oMasked[x][1]; fields[z]= new Array(); fields[z][0] = oMasked[x][0]; fields[z][1] = oMasked[x][2]; } else { var tMsg = oMasked[x][1].substring(0, index); // fields[z] = tMsg.replace("##", a[1]); fields[z]= new Array(); fields[z][0] = oMasked[x][0]; fields[z][1] = tMsg.replace("##", a[1]); } isValid = false; first = true; if(z == 0) { focusField = field; } ++z; break; } } } if(intcount2 == 0) { intcount2 = intcount0; } var b = value.indexOf("."); if(first == false) { if(b>=0) { for(var i = b + 1; i < value.length; ++i) { if((value.charAt(i) >='0')&&(value.charAt(i) <= '9')) { ++intcount1; } } if(intcount1 > a[1]) { var index = oMasked[x][1].indexOf("|"); if(index < 0) { // fields[z] = oMasked[x][1]; fields[z]= new Array(); fields[z][0] = oMasked[x][0]; fields[z][1] = oMasked[x][2]; } else { var tMsg = oMasked[x][1].substring(0, index); // fields[z] = tMsg.replace("##", a[1]); fields[z]= new Array(); fields[z][0] = oMasked[x][0]; fields[z][1] = tMsg.replace("##", a[1]); } isValid = false; second = true; if(z == 0) { focusField = field; } ++z; } } } if((first == first)&&(second == false)) { if(intcount2 > a[0] - a[1]) { var tNum = ""; for(var ab = 0; ab < a[0] - a[1]; ++ab) { tNum += "9"; } tNum += "."; for(var ba = 0; ba < a[1]; ++ba) { tNum += "9"; } var index = oMasked[x][1].indexOf("|"); if(index < 0) { // fields[z] = oMasked[x][1]; fields[z]= new Array(); fields[z][0] = oMasked[x][0]; fields[z][1] = oMasked[x][2]; } else { var tMsg = oMasked[x][1].substring(index + 1); // fields[z] = tMsg.replace("##", tNum); fields[z]= new Array(); fields[z][0] = oMasked[x][0]; fields[z][1] = tMsg.replace("##", tNum); } isValid = false; if(z == 0) { focusField = field; } ++z; } } } } } } if (fields.length > 0) { isValid=false; if(focusField != null) { focusField.focus(); } // alert(fields.join('\n')); displayValidateMessage(fields); } return isValid; } function validateDate(form, paramsFunctionName) { var isValid = true; var focusField = null; var i = 0; var fields = new Array(); var formName = form.getAttributeNode("name"); oDate = eval('new ' + paramsFunctionName + '_DateValidations()'); for (x in oDate) { var field = form[oDate[x][0]]; var value = trim(field.value); var deleteIndicator = oDate[x][1]; var checkBoxValue = isCheck(field); if(value.length == 0) { continue; } var datePattern = oDate[x][3]("datePatternStrict"); //if((checkBoxValue == false && deleteIndicator == "true" ) || deleteIndicator == "false") { if((field.type == 'text' || field.type == 'textarea') && (value.length > 0) && (datePattern.length > 0) && field.disabled == false) { var MONTH = "MM"; var DAY = "dd"; var YEAR = "yyyy"; var orderMonth = datePattern.indexOf(MONTH); var orderDay = datePattern.indexOf(DAY); var orderYear = datePattern.indexOf(YEAR); if((orderDay < orderYear && orderDay > orderMonth)) { var iDelim1 = orderMonth + MONTH.length; var iDelim2 = orderDay + DAY.length; var delim1 = datePattern.substring(iDelim1, iDelim1 + 1); var delim2 = datePattern.substring(iDelim2, iDelim2 + 1); if (iDelim1 == orderDay && iDelim2 == orderYear) { dateRegexp = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$"); } else if (iDelim1 == orderDay) { dateRegexp = new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$"); } else if (iDelim2 == orderYear) { dateRegexp = new RegExp("^(\\d{1,2})[" + delim1 + "](\\d{2})(\\d{4})$"); } else { dateRegexp = new RegExp("^(\\d{1,2})[" + delim1 + "](\\d{1,2})[" + delim2 + "](\\d{4})$"); dateRegexp1 = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$"); } var matched = dateRegexp.exec(value); if(matched == null) { matched = dateRegexp1.exec(value); } if(matched != null) { if(!isValidDate(matched[2], matched[1], matched[3])) { if (i == 0) { focusField = form[oDate[x][0]]; } // fields[i++] = oDate[x][1]; fields[i]= new Array(); fields[i][0] = oDate[x][0]; fields[i][1] = oDate[x][2]; i++; isValid = false; } } else { if (i == 0) { focusField = form[oDate[x][0]]; } // fields[i++] = oDate[x][1]; fields[i]= new Array(); fields[i][0] = oDate[x][0]; fields[i][1] = oDate[x][2]; i++; isValid = false; } } else if((orderMonth < orderYear && orderMonth > orderDay)) { var iDelim1 = orderDay + DAY.length; var iDelim2 = orderMonth + MONTH.length; var delim1 = datePattern.substring(iDelim1, iDelim1 + 1); var delim2 = datePattern.substring(iDelim2, iDelim2 + 1); if (iDelim1 == orderMonth && iDelim2 == orderYear) { dateRegexp = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$"); } else if(iDelim1 == orderMonth) { dateRegexp = new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$"); } else if(iDelim2 == orderYear) { dateRegexp = new RegExp("^(\\d{1,2})[" + delim1 + "](\\d{2})(\\d{4})$"); } else { dateRegexp = new RegExp("^(\\d{1,2})[" + delim1 + "](\\d{1,2})[" + delim2 + "](\\d{4})$"); dateRegexp1 = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$"); } var matched = dateRegexp.exec(value); if(matched == null) { matched = dateRegexp1.exec(value); } if(matched != null) { if(!isValidDate(matched[1], matched[2], matched[3])) { if(i == 0) { focusField = form[oDate[x][0]]; } // fields[i++] = oDate[x][1]; fields[i]= new Array(); fields[i][0] = oDate[x][0]; fields[i][1] = oDate[x][2]; i++; isValid = false; } } else { if (i == 0) { focusField = form[oDate[x][0]]; } // fields[i++] = oDate[x][1]; fields[i]= new Array(); fields[i][0] = oDate[x][0]; fields[i][1] = oDate[x][2]; i++; isValid = false; } } else if ((orderMonth > orderYear && orderMonth < orderDay)) { var iDelim1 = orderYear + YEAR.length; var iDelim2 = orderMonth + MONTH.length; var delim1 = datePattern.substring(iDelim1, iDelim1 + 1); var delim2 = datePattern.substring(iDelim2, iDelim2 + 1); if (iDelim1 == orderMonth && iDelim2 == orderDay) { dateRegexp = new RegExp("^(\\d{4})(\\d{2})(\\d{2})$"); } else if (iDelim1 == orderMonth) { dateRegexp = new RegExp("^(\\d{4})(\\d{1,2})[" + delim2 + "](\\d{1,2})$"); } else if (iDelim2 == orderDay) { dateRegexp = new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})(\\d{2})$"); } else { dateRegexp = new RegExp("^(\\d{4})[" + delim1 + "](\\d{1,2})[" + delim2 + "](\\d{1,2})$"); dateRegexp1 = new RegExp("^(\\d{4})(\\d{2})(\\d{2})$"); } var matched = dateRegexp.exec(value); if(matched == null) { matched = dateRegexp1.exec(value); } if(matched != null) { if (!isValidDate(matched[3], matched[2], matched[1])) { if (i == 0) { focusField = form[oDate[x][0]]; } // fields[i++] = oDate[x][1]; fields[i]= new Array(); fields[i][0] = oDate[x][0]; fields[i][1] = oDate[x][2]; i++; isValid = false; } } else { if (i == 0) { focusField = form[oDate[x][0]]; } // fields[i++] = oDate[x][1]; fields[i]= new Array(); fields[i][0] = oDate[x][0]; fields[i][1] = oDate[x][2]; i++; isValid = false; } } else { if (i == 0) { focusField = form[oDate[x][0]]; } // fields[i++] = oDate[x][1]; fields[i]= new Array(); fields[i][0] = oDate[x][0]; fields[i][1] = oDate[x][2]; i++; isValid = false; } } //} } if (fields.length > 0) { isValid=false; if(focusField != null) { focusField.focus(); } // alert(fields.join('\n')); displayValidateMessage(fields); } return isValid; } function validateByte(form, paramsFunctionName) { var isValid = true; var focusField = null; var i = 0; var fields = new Array(); var formName = form.getAttributeNode("name"); oByte = eval('new ' + paramsFunctionName + '_ByteValidations()'); // oByte = new ByteValidations(); for (x in oByte) { var field = form[oByte[x][0]]; var deleteIndicator = oByte[x][1]; var checkBoxValue = isCheck(field); if((checkBoxValue == false && deleteIndicator == "true" ) || deleteIndicator == "false") { if ((field.type == 'text' || field.type == 'textarea' || field.type == 'select-one' || field.type == 'radio') && field.disabled == false) { var value = ''; // get field's value if (field.type == "select-one") { var si = field.selectedIndex; if (si >= 0) { value = field.options[si].value; } } else { value = field.value; } value=trim(value); if(value.length == 0){ continue; } if (value.length > 0) { if (!isAllDigits(value)) { isValid = false; if (i == 0) { focusField = field; } // fields[i++] = oByte[x][1]; fields[i]= new Array(); fields[i][0] = oByte[x][0]; fields[i][1] = oByte[x][2]; i++; } else { var iValue = parseInt(value); if (isNaN(iValue) || !(iValue >= -128 && iValue <= 127)) { if (i == 0) { focusField = field; } // fields[i++] = oByte[x][1]; fields[i]= new Array(); fields[i][0] = oByte[x][0]; fields[i][1] = oByte[x][2]; i++; isValid = false; } } } } } } if(fields.length > 0) { isValid = false; if(focusField != null) { focusField.focus(); } // alert(fields.join('\n')); displayValidateMessage(fields); } return isValid; } function validateShort(form, paramsFunctionName) { var isValid = true; var focusField = null; var i = 0; var fields = new Array(); var formName = form.getAttributeNode("name"); oShort = eval('new ' + paramsFunctionName + '_ShortValidations()'); // oShort = new ShortValidations(); for (x in oShort) { var field = form[oShort[x][0]]; var deleteIndicator = oShort[x][1]; var checkBoxValue = isCheck(field); if((checkBoxValue == false && deleteIndicator == "true" ) || deleteIndicator == "false") { if ((field.type == 'text' || field.type == 'textarea' || field.type == 'select-one' || field.type == 'radio') && field.disabled == false) { var value = ''; // get field's value if (field.type == "select-one") { var si = field.selectedIndex; if (si >= 0) { value = field.options[si].value; } } else { value = field.value; } value=trim(value); if(value.length == 0) { continue; } if (value.length > 0) { if (!isAllDigits(value)) { isValid = false; if (i == 0) { focusField = field; } // fields[i++] = oShort[x][1]; fields[i]= new Array(); fields[i][0] = oShort[x][0]; fields[i][1] = oShort[x][2]; i++; } else { var iValue = parseInt(value); if (isNaN(iValue) || !(iValue >= -32768 && iValue <= 32767)) { if (i == 0) { focusField = field; } // fields[i++] = oShort[x][1]; fields[i]= new Array(); fields[i][0] = oShort[x][0]; fields[i][1] = oShort[x][2]; i++; isValid = false; } } } }} } if(fields.length > 0) { isValid = false; if(focusField != null) { focusField.focus(); } // alert(fields.join('\n')); displayValidateMessage(fields); } return isValid; } function validateRadioButtonRequired(form, paramsFunctionName) { var isValid=true; // Add this variable to record all radiobutton group name that not checked . var field; var j = 0; var iCount = 0; var formName = form.getAttributeNode("name"); var fields = new Array(); oRadioButtonRequired = eval('new ' + paramsFunctionName + '_RadioButtonRequiredValidations()'); // oRadioButtonRequired = new radioButtonRequired(); for (x in oRadioButtonRequired) { isValid = false; field = form[oRadioButtonRequired[x][0]]; iCount = field.length; if ( iCount > 1 ){ for ( var i = 0; i < iCount; i++ ) { if ( field[i].checked ) { isValid = true; break; } } } else if ( iCount == null || iCount == 0 ) { if ( field.checked ) { isValid = true; } } if( !isValid ){ // fields[j++] = oRadioButtonRequired[x][1]; fields[j]= new Array(); fields[j][0] = oRadioButtonRequired[x][0]; fields[j][1] = oRadioButtonRequired[x][1]; j++; } } if (fields.length > 0) { isValid = false; // alert(fields.join('\n')); displayValidateMessage(fields); } return isValid; } function validateCheckboxRequired(form, paramsFunctionName) { var isValid=true; var fields = new Array(); var field; var j = 0; var iCount = 0; var formName = form.getAttributeNode("name"); oCheckboxRequired = eval('new ' + paramsFunctionName + '_CheckboxRequiredValidations()'); for (x in oCheckboxRequired) { isValid=false; field = form[oCheckboxRequired[x][0]]; iCount = field.length; // if ( field == null ) { // alert ( oCheckboxRequired[x][1] + "hello \n" ); // return false; // } if ( iCount > 1 ) { for ( var i = 0; i < iCount; i++ ) { if ( field[i] != null) { if ( field[i].checked ) { isValid = true; break; } } } } else if ( iCount == null || iCount == 0 ) { if ( field.checked ) { isValid = true; } } if( !isValid ){ fields[j]= new Array(); fields[j][0] = oCheckboxRequired[x][0]; fields[j][1] = oCheckboxRequired[x][1]; j++; } } if (fields.length > 0) { isValid = false; displayValidateMessage(fields); } return isValid; } function validateFromToDate(form, paramsFunctionName) { return validateFromToDateC(form, paramsFunctionName + '_FromToDateValidations()'); } function validateFromToDateRange(form, paramsFunctionName) { return validateFromToDateC(form, paramsFunctionName + '_FromToDateRangeValidations()'); } function validateFromToDateC(form,paramsFunctionName) { var isValid=true; var focusField=null; var i=0; var fields=new Array(); var formName=form.getAttributeNode("name"); var abResult=new Array(); var iLoop=0; oFromToDate=eval('new '+paramsFunctionName); var fromMatched=null; var toMatched=null; for(x in oFromToDate) { var field = form[oFromToDate[x][0]]; var deleteIndicator = oFromToDate[x][1]; var checkBoxValue = isCheck(field); if((checkBoxValue == false && deleteIndicator == "true" ) || deleteIndicator == "false") { var datePattern=oFromToDate[x][3]("datePatternStrict"); var bAllowsSameDay=oFromToDate[x][3]("allowsSameDay"); var fromAndToRequired=oFromToDate[x][3]("fromAndToRequired"); var daysRange=oFromToDate[x][3]("daysRange"); var inputDateField=trim(oFromToDate[x][0]); var comparedDateField=oFromToDate[x][3]("comparedDate"); var comparedRule=oFromToDate[x][3]("comparedRule"); var sInputDate; var sComparedDate; var sToDateField; var sFromDateField; var sFromDate; var sToDate; if( typeof(fromAndToRequired)== "undefined" || fromAndToRequired=="false"){ if(trim(form.elements[inputDateField].value).length==0) { continue; } } if(validDate(inputDateField,datePattern)!=null) { sInputDate=inputDateField; }else { sInputDate=inputDateField=="Today"?dateFormat(new Date(),datePattern):trim(form.elements[inputDateField].value); } if(validDate(comparedDateField,datePattern)!=null) { sComparedDate=comparedDateField; }else { sComparedDate="Today"==comparedDateField?dateFormat(new Date(),datePattern):trim(form.elements[comparedDateField].value); } if( typeof(fromAndToRequired)!= "undefined" && fromAndToRequired=="true"){ if((sInputDate==null||sInputDate=="")&&(sComparedDate!=null && sComparedDate!="")) { if(focusField==null) { if((form[oFromToDate[x][0]]!=null)&&(form[oFromToDate[x][0]].type=='text')) focusField=form[oFromToDate[x][0]]; } fields[i]= new Array(); fields[i][0] = oFromToDate[x][0]; fields[i][1] = oFromToDate[x][3]("inputReqErrMsg");; i++; isValid=false; continue; } if((sComparedDate==null||sComparedDate=="")&&(sInputDate!=null && sInputDate!="")) { if(focusField==null) { if((form[comparedDateField]!=null)&&(form[comparedDateField].type=='text')) focusField=form[comparedDateField]; } fields[i]= new Array(); fields[i][0] = comparedDateField; fields[i][1] = oFromToDate[x][3]("compareReqErrMsg");; i++; isValid=false; continue; } } if(sInputDate==null||sComparedDate==null||sInputDate==""||sComparedDate=="") { continue; } toMatched=validDate(sComparedDate,datePattern); if(toMatched==null) { if(focusField==null) { if((form[oFromToDate[x][0]]!=null)&&(form[oFromToDate[x][0]].type=='text')) focusField=form[oFromToDate[x][0]]; } fields[i]= new Array(); fields[i][0] = oFromToDate[x][0]; fields[i][1] = oFromToDate[x][2]; i++; // fields[i++]=oFromToDate[x][1]; isValid=false; }else { fromMatched=validDate(sInputDate,datePattern); if(fromMatched==null) { if(focusField==null) { if((form[oFromToDate[x][0]]!=null)&&(form[oFromToDate[x][0]].type=='text')) focusField=form[oFromToDate[x][0]]; } fields[i]= new Array(); fields[i][0] = oFromToDate[x][0]; fields[i][1] = oFromToDate[x][2]; i++; isValid=false; }else { if(fromMatched[2].length==1) { fromMatched[2]="0"+fromMatched[2]; } if(fromMatched[1].length==1) { fromMatched[1]="0"+fromMatched[1]; } if(toMatched[2].length==1) { toMatched[2]="0"+toMatched[2]; } if(toMatched[1].length==1) { toMatched[1]="0"+toMatched[1]; } var sFromToken=fromMatched[3]+fromMatched[2]+fromMatched[1]; var sToToken=toMatched[3]+toMatched[2]+toMatched[1]; var iInputDate=parseInt(sFromToken); var sDate=toMatched[1]; var sMonth=toMatched[2]; if(sDate.charAt(0)=='0') { sDate=sDate.charAt(1); } if(sMonth.charAt(0)=='0') { sMonth=sMonth.charAt(1); } var iDate=parseInt(sDate)+parseInt(daysRange); var iMonth=parseInt(sMonth); var iYear=parseInt(toMatched[3]); while(!isValidDate(iDate,iMonth,iYear)) { if(iMonth>12) { iMonth=iMonth-12; iYear=iYear+1; } if(iMonth==4||iMonth==6||iMonth==9||iMonth==11) { if(iDate>30) { iDate=iDate-30; iMonth=iMonth+1; } }else if(iMonth==2) { if((iYear%4)==0) { if(iDate>29) { iDate=iDate-29; iMonth=iMonth+1; } }else { if(iDate>28) { iDate=iDate-28; iMonth=iMonth+1; } } }else { if(iDate>31) { iDate=iDate-31; iMonth=iMonth+1; } } } if(iMonth<10) { iMonth="0"+iMonth; } if(iDate<10) { iDate="0"+iDate; } var iComparedDate=parseInt(iYear+""+iMonth+""+iDate); if(bAllowsSameDay=='true') { if(comparedRule=='E') { if(iInputDate<=iComparedDate) { isValid=true; }else { fields[i]= new Array(); fields[i][0] = oFromToDate[x][0]; fields[i][1] = oFromToDate[x][2]; i++; isValid=false; if(focusField==null) { if((form[oFromToDate[x][0]]!=null)&&(form[oFromToDate[x][0]].type=='text')) focusField=form[oFromToDate[x][0]]; } } }else if(comparedRule=='L') { if(iInputDate>=iComparedDate) { isValid=true; }else { fields[i]= new Array(); fields[i][0] = oFromToDate[x][0]; fields[i][1] = oFromToDate[x][2]; i++; isValid=false; if(focusField==null) { if((form[oFromToDate[x][0]]!=null)&&(form[oFromToDate[x][0]].type=='text')) focusField=form[oFromToDate[x][0]]; } } } }else { if(comparedRule=='E') { if(iInputDateiComparedDate) { isValid=true; }else { fields[i]= new Array(); fields[i][0] = oFromToDate[x][0]; fields[i][1] = oFromToDate[x][2]; i++; isValid=false; if(focusField==null) { if((form[oFromToDate[x][0]]!=null)&&(form[oFromToDate[x][0]].type=='text')) focusField=form[oFromToDate[x][0]]; } } } } iLoop++; } } } } if(fields.length>0) { isValid=false; focusField.focus(); // alert(fields.join('\n')); displayValidateMessage(fields); } return isValid; } // TODO yuanbin // //////////////////////////////////////////////////////// // //////////////////////////////////////////////////////// function validateRelationRequired(form, paramsFunctionName) { var isValid = true; var focusField = null; var i = 0; var fields = new Array(); oArrayBool = eval('new ' + paramsFunctionName + '_RelationRequiredValidations()'); var fromMatched = null; var toMatched = null; for(x in oArrayBool) { var required = oArrayBool[x][2]("required"); var otarget1 = oArrayBool[x][0]; var otarget2 = oArrayBool[x][2]("target"); var target1 = trim(form.elements[otarget1].value); var target2 = trim(form.elements[otarget2].value); if(((target1==null)||(target1==""))&&((target2!=null)&&(target2!=""))) { if (i == 0) { focusField = form.elements[otarget1]; } fields[i++] = oArrayBool[x][1]; isValid = false; } else if(((target1!=null)&&(target1!=""))&&((target2==null)||(target2==""))) { if (i == 0) { focusField = form.elements[otarget2]; } fields[i++] = oArrayBool[x][1]; isValid = false; } } if (fields.length > 0) { focusField.focus(); alert(fields.join('\n')); } return isValid; } function validateCodeCheckboxRequired(form, paramsFunctionName) { var message = ""; var field; var formName = form.getAttributeNode("name"); oCheckboxRequired = eval('new ' + paramsFunctionName + '_CodeCheckboxRequiredValidations()'); for (x in oCheckboxRequired) { var isValid=false; field = oCheckboxRequired[x][0]; if ( field == null ) { alert ( oCheckboxRequired[x][1] + "\n" ); return false; } var fields = (trim(field)).split(' '); for(y in fields) { if(document.getElementById(fields[y]) == null) { continue; } if(document.getElementById(fields[y]).checked) { isValid = true; break; } } if(!isValid) { message += oCheckboxRequired[x][1] + "\n"; } } if ( message != "" ) { alert ( message ); return false; } return true; } function validateCodeRadioRequired(form, paramsFunctionName) { var message = ""; var field; var formName = form.getAttributeNode("name"); oCheckboxRequired = eval('new ' + paramsFunctionName + '_CodeRadioRequiredValidations()'); for (x in oCheckboxRequired) { var isValid=false; field = oCheckboxRequired[x][0]; if ( field == null ) { alert ( oCheckboxRequired[x][1] + "\n" ); return false; } var fields = (trim(field)).split(' '); for(y in fields) { if(document.getElementById(fields[y]) == null) { continue; } if(document.getElementById(fields[y]).checked) { isValid = true; break; } } if(!isValid) { message += oCheckboxRequired[x][1] + "\n"; } } if ( message != "" ) { alert ( message ); return false; } return true; } function validateCodeDropdownListRequired(form, paramsFunctionName) { var message = ""; var field; var formName = form.getAttributeNode("name"); oCheckboxRequired = eval('new ' + paramsFunctionName + '_CodeDropdownListRequiredValidations()'); for (x in oCheckboxRequired) { var isValid=false; field = oCheckboxRequired[x][0]; if ( field == null ) { alert ( oCheckboxRequired[x][1] + "\n" ); return false; } if(document.getElementById(field) == null) { continue; } if(document.getElementById(field).value == '') { message += oCheckboxRequired[x][1] + "\n"; } } if ( message != "" ) { alert ( message ); return false; } return true; } function isValidUINNRIC(id){ id = id.toUpperCase(); var prefix = id.substring(0, 1); if (prefix == 'S' || prefix == 'T') { var result = isValidUINFIN(id); if(result == 0){ return true; } } return false; }