var PASSWORD_MIN_LENGTH = 5; var ACCEPTABLE_DIGITS = "0123456789"; var ACCEPTABLE_PHONE_DELIMITERS = ".()- "; // non-digit characters which // are allowed in phone numbers function jsv_IsEmpty(aTextField) { if(aTextField.value!="") { return false; } else { return true; } } function jsv_IsSame(obj_source, obj_toCheck, field_name) { //msg_err='The Confirm '+ field_name +' must be same as the given '+ field_name; msg_err=field_name +' mismatch'; if(obj_source.value==obj_toCheck.value) { return true; } else { alert(msg_err); obj_source.focus(); return false; } } /************************************************************************************************* * Function: * Description: * Created By: Brian Paonessa (brian.paonessa@vediorna.com) * * Arguments: * < to come > * *************************************************************************************************/ function js_stripCharsInBag(ls_chars, ls_bag) { var i; var ls_returnString = ""; // Search through string's characters one by one. // If character is not in bag, append to returnString. for (i = 0; i < ls_chars.length; i++) { // Check that current character isn't whitespace. var c = ls_chars.charAt(i); if (ls_bag.indexOf(c) == -1) ls_returnString += c; } return ls_returnString; }// END OF FUNCTION ////////////////////////////////////////// /************************************************************************************************* * Function: js_findPhoneExtStartPos * Description: * Created By: Brian Paonessa (brian.paonessa@vediorna.com) * * Arguments: * as_phone * *************************************************************************************************/ function js_findPhoneExtStartPos(as_phone, as_maxlen) { var ls_c; var ll_pos; // FOR EACH CHAR // for (i = 0; i < as_phone.length; i++) { ls_c = as_phone.charAt(i); //GET NEXT CHAR if ((ls_c == 'x') || (ls_c == 'X')) {return i;} } // Last change, this is if the extention was not given a delimiter if (as_phone.length > as_maxlen) {return as_maxlen;} return -1; }// END OF FUNCTION ////////////////////////////////////////// /************************************************************************************************* * Function: js_makeStripedPhonePretty * Description: * Created By: Brian Paonessa (brian.paonessa@vediorna.com) * * Arguments: * as_phone * *************************************************************************************************/ function js_makeStripedPhonePretty(as_phone) { return as_phone.substring(0,3) + '-' + as_phone.substring(3,6) + '-' + as_phone.substring(6,10) }// END OF FUNCTION ////////////////////////////////////////// /************************************************************************************************* * Function: * Description: * Created By: Brian Paonessa (brian.paonessa@vediorna.com) * * Arguments: * < to come > * *************************************************************************************************/ function isInteger(ls_value) { var i; for (i = 0; i < ls_value.length; i++) { // Check that current character is number. var c = ls_value.charAt(i); if (((c < "0") || (c > "9"))) return false; } return true; // All characters are numbers. }// END OF FUNCTION ////////////////////////////////////////// function jsv_checkField_isEmail_simple(obj_toCheck, msg_err, msg_blank) { if (msg_blank+'x'=='x') {msg_blank='Email address is required';} if (msg_err+'x'=='x') {msg_err='The email address you have provided does not appear to be valid.';} // Make sure the field is not blank first if (!jsv_checkField_hasValue(obj_toCheck, msg_blank, '')) { return false; } var lreg_filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/; // Is it an email address? if (!(lreg_filter.test(obj_toCheck.value))) { alert(msg_err); obj_toCheck.focus(); return false; } return true; } function jsv_checkField_hasValue(obj_toCheck, msg_err, msg_fieldName) { if (msg_fieldName+'x'=='x') {msg_fieldName=obj_toCheck.name;} if (msg_err+'x'=='x') {msg_err='This field is required: ' + msg_fieldName;} msg_invalid='Invalid Characters!'; if(jsv_IsEmpty(obj_toCheck)) { alert(msg_err); obj_toCheck.focus(); return false; } else if(jsv_IsValid(obj_toCheck)==false) { alert(msg_invalid); obj_toCheck.focus(); return false; } return true; } function jsv_checkField_compareDate(obj_toCheck, obj_comparefield, msg_fieldName1, msg_fieldName2, compareOperator) { var fDate = new Date(obj_toCheck.value); if(obj_comparefield!=null && obj_comparefield!='') { var tDate = new Date(obj_comparefield.value); } else { var today = new Date(); var d = today.getDate(); var m = (today.getMonth()+1); var y = today.getFullYear(); d = (d < 10) ? '0' + d : d; m = (m < 10) ? '0' + m : m; var todayDate =m + '/'+ d + '/' + y; var tDate = new Date(todayDate); } if((compareOperator=='gt') && (fDate > tDate)) { alert(msg_fieldName1 + ' must be less than or equal to '+ msg_fieldName2); obj_toCheck.focus(); return false; } else if((compareOperator=='lt') && (fDate < tDate)) { alert(msg_fieldName1 + ' must be greater than or equal to '+ msg_fieldName2); obj_toCheck.focus(); return false; } else if((compareOperator=='gte') && (fDate >= tDate)) { alert(msg_fieldName1 + ' must be less than '+ msg_fieldName2); obj_toCheck.focus(); return false; } else if((compareOperator=='lte') && (fDate <= tDate)) { alert(msg_fieldName1 + ' must be greater than '+ msg_fieldName2); obj_toCheck.focus(); return false; } else if((compareOperator=='eq') && ((fDate > tDate) || (fDate < tDate))) { alert(msg_fieldName1 + ' must be equal to '+ msg_fieldName2); obj_toCheck.focus(); return false; } return true; } function jsv_IsValid(obj_toCheck) { var i; for (i = 0; i < obj_toCheck.value.length; i++) { // Check that current character is number. var c = obj_toCheck.value.charAt(i); if (((c == ">") || (c == "<"))) return false; } return true; } /************************************************************************************************* * Function: js_checkField_isPhone_Simple * Description: * Created By: Brian Paonessa (brian.paonessa@vediorna.com) * * Arguments: * ao_toCheck * ab_format * ab_blankOk * as_errFormat * as_errBlank * *************************************************************************************************/ function js_checkField_isPhone_Simple(ao_toCheck, ab_format, ab_blankOk, as_errFormat, as_errBlank) { var ACCEPTABLE_PHONE_LENGTH = 10; var ls_ext = ''; var ll_extPos = -1; var ll_noDilmAdjust = 1; var ls_phone=js_stripCharsInBag(ao_toCheck.value, ACCEPTABLE_PHONE_DELIMITERS); if (jsv_IsEmpty(ao_toCheck)) { if (ab_blankOk) { return true; } else { alert(as_errBlank); ao_toCheck.focus(); return false; } } if (ls_phone.charAt(0) == '1') {ls_phone=ls_phone.substring(1,ls_phone.length);} var ll_pos = ls_phone.indexOf('ext',0); if (ll_pos > 0) { ls_phone = ls_phone.substring(0, ll_pos) + 'x' + ls_phone.substr(ll_pos+3, (ls_phone.length-(ll_pos+3))); } var ll_pos = ls_phone.indexOf('ex',0); if (ll_pos > 0) { ls_phone = ls_phone.substring(0, ll_pos) + 'x' + ls_phone.substr(ll_pos+2, (ls_phone.length-(ll_pos+2))); } //FIND AND REMOVE EXTENTION With delimiter ll_extPos = js_findPhoneExtStartPos(ls_phone, ACCEPTABLE_PHONE_LENGTH); if (ll_extPos > 0) { if (!(isInteger(ls_phone))) { ls_ext = ls_phone.substring(ll_extPos+1,(ls_phone.length)); ls_phone = ls_phone.substring(0,((ls_phone.length-ls_ext.length)-1)); } else { ls_ext = ls_phone.substring(ll_extPos,(ls_phone.length)); ls_phone = ls_phone.substring(0,(ls_phone.length-ls_ext.length)); } if (isInteger(ls_ext) != true) { if(as_errFormat!=''){alert(as_errFormat);}else{alert(ls_phone);}; ao_toCheck.focus(); return false; } //Append the "x" and clear if we got nothing if (ls_ext.length > 0) {ls_ext = ' x'+ls_ext} } if (((isInteger(ls_phone)) && (ls_phone.length == ACCEPTABLE_PHONE_LENGTH)) != true) { if(as_errFormat!=''){alert(as_errFormat);}else{alert(ls_phone);}; ao_toCheck.focus(); return false; } if (ab_format) {ao_toCheck.value=js_makeStripedPhonePretty(ls_phone)+ls_ext} return true; } function jsv_checkField_isZipCode(obj_toCheck, msg_err, msg_fieldName) { if (msg_fieldName+'x'=='x') {msg_fieldName=obj_toCheck.name;} if (msg_err+'x'=='x') {msg_err='This field is required: ' + msg_fieldName;} if(jsv_IsEmpty(obj_toCheck)) { alert(msg_err); obj_toCheck.focus(); return false; } else if(obj_toCheck.value.length!=5) { alert('You must enter a valid Zip Code'); obj_toCheck.focus(); return false; } return true; } function jsv_checkRadio_oneSelected(obj_toCheck, s_fieldName, s_err){ var bln_anySelected = false; var i; if (s_fieldName+'x'=='x') {s_fieldName=s_fieldName} if (s_err+'x'=='x') {s_err='You must select a value for ' + s_fieldName} // COUNT SELECTED VALUES // var arrayOfCheckBoxes= obj_toCheck.getElementsByTagName("input"); for (i = 0; i < arrayOfCheckBoxes.length; i++) { if (arrayOfCheckBoxes[i].checked) { bln_anySelected = true; } } // ERROR IF NONE SELECTED // if (!bln_anySelected) { alert(s_err); obj_toCheck.focus(); return false; } return bln_anySelected; } function jsv_isValidDate(obj_toCheck, msgStr) { // Checks for the following valid date formats: // MM/DD/YY MM/DD/YYYY MM-DD-YY MM-DD-YYYY // Also separates date into month, day, and year variables var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/; // To require a 4 digit year entry, use this line instead: // var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; var matchArray = obj_toCheck.value.match(datePat); // is the format ok? if (matchArray == null) { alert(msgStr+": Date is not in a valid format."); obj_toCheck.focus(); obj_toCheck.value=''; return false; } month = matchArray[1]; // parse date into variables day = matchArray[3]; year = matchArray[4]; if (month < 1 || month > 12) { // check month range alert(msgStr+": Month must be between 1 and 12."); obj_toCheck.focus(); obj_toCheck.value=''; return false; } if (day < 1 || day > 31) { alert(msgStr+": Day must be between 1 and 31."); obj_toCheck.focus(); obj_toCheck.value=''; return false; } if ((month==4 || month==6 || month==9 || month==11) && day==31) { alert(msgStr+": Month "+month+" doesn't have 31 days!") obj_toCheck.focus(); obj_toCheck.value=''; return false } if (month == 2) { // check for february 29th var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); if (day>29 || (day==29 && !isleap)) { alert(msgStr+": February " + year + " doesn't have " + day + " days!"); obj_toCheck.focus(); obj_toCheck.value=''; return false; } } return true; // date is valid } function jsv_IsNumeric(obj_toCheck, msg_fieldName) { return jsv_checkIf_charsInString(obj_toCheck, '0123456789.',msg_fieldName) } function jsv_checkIf_charsInString(obj_toCheck, str_theList,msg_fieldName) { var str_theCharToCheck; var str_toCheck = obj_toCheck.value; // FOR EACH CHAR // for (i = 0; i < str_toCheck.length; i++) { str_theCharToCheck = str_toCheck.charAt(i); //GET NEXT CHAR if (str_theList.indexOf(str_theCharToCheck) == -1) //IS IN LIST? { alert('This field must be in Numeric: '+ msg_fieldName); obj_toCheck.focus(); return false; break; } } return true; }