function trim(str) { return str.replace(/^\s*|\s*$/g,""); } function isRadioSelected(radioGroup) { if (!radioGroup.length) { return radioGroup.checked; } for (var i = 0; i < radioGroup.length; i++) { if (radioGroup[i].checked) { return true; } } return false; } function isCheckboxSelected(checkboxGroup) { return isRadioSelected(checkboxGroup); } function isEmpty(field) { if (field.value == '') { return true; } else { return false; } } function isEmail(strValue) { var objRegExp = /^[-+_a-z0-9.]+@[-a-z0-9.]+/i; //check for valid email return objRegExp.test(strValue); } function isInteger(strValue) { var objRegExp = /(^-?\d+$)/; //check for integer characters return objRegExp.test(strValue); } function isNumeric(strValue) { var objRegExp = /(^-?\d+\.\d*$)|(^-?\d+$)|(^-?\.\d+$)/; //check for numeric characters return objRegExp.test(strValue); } function isAlpha(strValue) { var objRegExp = /^[a-z]+$/i; return objRegExp.test(strValue); } function isAlphaNumeric(strValue) { var objRegExp = /^[a-z0-9]+$/i; return objRegExp.test(strValue); } function match(strValue, strMatchPattern) { var objRegExp = new RegExp( strMatchPattern); //check if string matches pattern return objRegExp.test(strValue); } function removeCommas(strValue) { var objRegExp = /,/g; //search for commas globally //replace all matches with empty strings return strValue.replace(objRegExp,''); } function removeCurrency(strValue) { var objRegExp = /\(/; var strMinus = ''; //check if negative if(objRegExp.test(strValue)){ strMinus = '-'; } objRegExp = /\)|\(|[,]/g; strValue = strValue.replace(objRegExp,''); if(strValue.indexOf('$') >= 0){ strValue = strValue.substring(1, strValue.length); } return strMinus + strValue; } function isCurrency(strValue) { return isNumeric(removeCurrency(strValue)); } function removeCharacters(strValue, strMatchPattern) { var objRegExp = new RegExp( strMatchPattern, 'gi' ); //replace passed pattern matches with blanks return strValue.replace(objRegExp,''); } function clearErrors(form_name) { var form = document.forms[form_name]; var labels = form.getElementsByTagName('th'); for (var i = 0; i < labels.length; i++) { if (labels[i].className == 'error') { labels[i].className = 'label'; } } // clear error message document.getElementById(form_name + '_error_list').innerHTML = ''; } var currentGroup = null; function startGroup(form_name, name, label) { var groupHeading = document.createElement('li'); groupHeading.innerHTML = label + ' has the following errors:'; document.getElementById(form_name + '_error_list').appendChild(groupHeading); currentGroup = document.createElement('ul'); } function endGroup(form_name, name) { if (currentGroup.childNodes.length > 1) { document.getElementById(form_name + '_error_list').appendChild(currentGroup); var labelElm = document.getElementById('label_' + name); if (labelElm && labelElm.className) { labelElm.className = 'error'; } } currentGroup = null; } function error(form_name, label, errorMessage) { document.getElementById(form_name + '_error_hint').style.display = 'inline'; var labelElm = document.getElementById('label_' + label); if (labelElm) { labelElm.className = 'error'; } // append error message var msg = document.createElement('li'); msg.innerHTML = errorMessage; if (currentGroup != null) { currentGroup.appendChild(msg); } else { document.getElementById(form_name + '_error_list').appendChild(msg); } } function isError(form_name, label, condition, errorMessage) { if (condition) { error(form_name, label, errorMessage); return true; } return false; }