Sign up for
Focalex
.
function validateAtLeastOneChecked( frm, field_name, custErr ) { var checkboxes_checked = 0; for (i=0; i< frm.elements.length; i++) { if (frm.elements[i].name == field_name) { if (frm.elements[i].checked) { checkboxes_checked = 1; } } } if (checkboxes_checked == 0) { return '-> ' + custErr + "\n"; } else { return ''; } } function validateEmail(email) { var emailPat=/^(.+)@(.+)$/; var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"; var validChars="\[^\\s" + specialChars + "\]"; var quotedUser="(\"[^\"]*\")"; var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/; var atom=validChars + '+'; var word="(" + atom + "|" + quotedUser + ")"; var userPat=new RegExp("^" + word + "(\\." + word + ")*$"); var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$"); var matchArray=email.match(emailPat); if (matchArray==null) { return false; } var user=matchArray[1]; var domain=matchArray[2]; if (user.match(userPat)==null) { return false; } var IPArray=domain.match(ipDomainPat); if (IPArray!=null) { for (var i=1;i<=4;i++) { if (IPArray[i]>255) { return false; } } return true; } var domainArray=domain.match(domainPat); if (domainArray==null) { return false; } var atomPat=new RegExp(atom,"g"); var domArr=domain.match(atomPat); var len=domArr.length; if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) { return false; } if (len<2) { return false; } return true; } function validateData(strValidateStr,objValue,custErr) { var strErr = ''; var epos = strValidateStr.search("="); var command = ""; var cmdvalue = ""; if(epos >= 0) { command = strValidateStr.substring(0,epos); cmdvalue = strValidateStr.substr(epos+1); } else { command = strValidateStr; } switch(command) { case "req": case "required": { if (eval(objValue.value.length) == 0) { if (!custErr || custErr.length == 0) { strErr = '-> ' + objValue.name + " : Required Field.\n"; } else { strErr = '-> ' + custErr + "\n"; } } break; } case "maxlength": case "maxlen": { if (eval(objValue.value.length) > eval(cmdvalue)) { if (!custErr || custErr.length == 0) { strErr = '-> ' + objValue.name + " : "+cmdvalue+" characters maximum." + "\n [Current length = " + objValue.value.length + " ].\n"; } else { strErr = '-> ' + custErr + "\n"; } } break; } case "minlength": case "minlen": { if (eval(objValue.value.length) < eval(cmdvalue)) { if (!custErr || custErr.length == 0) { strErr = '-> ' + objValue.name + " : " + cmdvalue + " characters minimum." + "\n [Current length = " + objValue.value.length + " ].\n"; } else { strErr = '-> ' + custErr + "\n"; } } break; } case "alnum": case "alphanumeric": { var charpos = objValue.value.search("[^A-Za-z0-9]"); if (objValue.value.length > 0 && charpos >= 0) { if (!custErr || custErr.length == 0) { strErr = objValue.name+": Only alpha-numeric characters allowed." + "\n [Error character position " + eval(charpos+1)+"]."; } else { strErr = '-> ' + custErr + "\n"; } } break; } case "num": case "numeric": { var charpos = objValue.value.search("[^0-9]"); if (objValue.value.length > 0 && charpos >= 0) { if (!custErr || custErr.length == 0) { strErr = '-> ' + objValue.name+": Only digits allowed " + "\n [Error character position " + eval(charpos+1)+"].\n"; } else { strErr = '-> ' + custErr + "\n"; } } break; } case "alphabetic": case "alpha": { var charpos = objValue.value.search("[^A-Za-z]"); if (objValue.value.length > 0 && charpos >= 0) { if (!custErr || custErr.length == 0) { strErr = '-> ' + objValue.name+": Only alphabetic characters allowed" + "\n [Error character position " + eval(charpos+1)+"].\n"; } else { strErr = '-> ' + custErr + "\n"; } } break; } case "email": { if (!validateEmail(objValue.value,strErr)) { if (!custErr || custErr.length == 0) { strErr = '-> ' + objValue.name+": Enter a valid Email address.\n"; } else { strErr = '-> ' + custErr + "\n"; } } break; } case "lt": case "lessthan": { if (isNaN(objValue.value)) { strErr = strError + '-> ' + objValue.name+": Should be a number.\n"; } else { if (eval(objValue.value) >= eval(cmdvalue)) { if (!custErr || custErr.length == 0) { strErr = '-> ' + objValue.name + " : value should be less than "+ cmdvalue +".\n"; } else { strErr = '-> ' + custErr + "\n"; } } } break; } case "gt": case "greaterthan": { if (isNaN(objValue.value)) { strErr = '-> ' + objValue.name+": Should be a number.\n"; } else { if (eval(objValue.value) <= eval(cmdvalue)) { if (!custErr || custErr.length == 0) { strErr = '-> ' + objValue.name + " : value should be greater than " + cmdvalue + ".\n"; } else { strErr = '-> ' + custErr + "\n"; } } } break; } case "regexp": { if (!objValue.value.match(cmdvalue)) { if (!custErr || custErr.length == 0) { strErr = '-> ' + objValue.name+": Invalid characters found.\n"; } else { strErr = '-> ' + custErr + "\n"; } } break; } case "notregexp": case "!regexp": { if (objValue.value.match(cmdvalue)) { if (!custErr || custErr.length == 0) { strErr = '-> ' + objValue.name+": Invalid characters found.\n"; } else { strErr = '-> ' + custErr + "\n"; } } break; } case "dontselect": { if (objValue.selectedIndex == null) { alert("BUG: dontselect command for non-select Item"); } else { if (objValue.selectedIndex == eval(cmdvalue)) { if (!custErr || custErr.length == 0) { strErr = '-> ' + objValue.name+": Please Select one option.\n"; } else { strErr = '-> ' + custErr + "\n"; } } } break; } } return strErr; } function validateForm(objFrm,arrObjDesc) { var strErr = ''; for(var itrobj=0; itrobj < arrObjDesc.length; itrobj++) { var strErr_element = ''; if(objFrm.elements.length <= itrobj) { alert("BUG: Obj descriptor for a non existent form element"); return false; } for (var itrdesc=0; itrdesc < arrObjDesc[itrobj].length ;itrdesc++) { if (strErr_element != '') { break; } strErr_element = validateData( arrObjDesc[itrobj][itrdesc][0], objFrm[itrobj], arrObjDesc[itrobj][itrdesc][1] ); } strErr = strErr + strErr_element; } return strErr; } //-- if using this method, you must specify the validation array //-- in reverse order as well function validateFormReverse(objFrm,arrObjDesc) { var strErr = ''; for(var itrobj=0; itrobj < arrObjDesc.length; itrobj++) { var strErr_element = ''; if(objFrm.elements.length <= itrobj) { alert("BUG: Obj descriptor for a non existent form element"); return false; } for (var itrdesc=0; itrdesc < arrObjDesc[itrobj].length ;itrdesc++) { if (strErr_element != '') { break; } strErr_element = validateData( arrObjDesc[itrobj][itrdesc][0], objFrm[objFrm.length-1-itrobj], arrObjDesc[itrobj][itrdesc][1] ); } strErr = strErr + strErr_element; } return strErr; } function displayErrors( header, strErr ) { if ((strErr) && (strErr.length > 0)) { alert( header + "\n" + strErr ); return true; } else { return false; } } function submit_new() { var validation_array = [ [], [], [ // email ['required','You must enter your email address in order to signup.'], ['email', 'Your email address appears to be invalid.'] ] ]; if (document.foca_pop.age != null) { validation_array[3] = []; validation_array[4] = [ [ "regexp=^(|1[3-9]|[2-9][0-9][0-9]?)$", "Your have entered an invalid age. (13+ and digits only)" ] ]; } var harris = 0; for (var i=0;i
200 More Topics Here
[
H O M E
]