//////////// =============== LOGIN VALIDATION =================== function loginvalidate(theform){ //validate function var chklogin = /^[A-Za-z0-9]+$/; var chkpasswd = /^[A-Za-z0-9\.@#^\_!$]+$/; var login = theform.loginid.value; var passwd = theform.passwd.value; var errors = []; if ((!chkminlength(login, 7)) || (!chkmaxlength(login, 10)) || (!chklogin.test(login))) { errors[errors.length] = "Login ID"; } if ((!chkminlength(passwd, 8)) || (!chkmaxlength(passwd, 25)) || (!chkpasswd.test(passwd))) { errors[errors.length] = "Password"; } if (errors.length > 0) { reportErrors(errors); return false; } else { return true; } } // validate function END //////////// =============== end LOGIN VALIDATION =================== //////////// =============== RECOVER PASS VALIDATION =================== function recpass(theform){ //validate function var chkalpha = /^[A-Za-z ]+$/; var chkalphadot = /^[A-Za-z\. ]+$/; var chknumbers = /^\d{4}$/; // 4 used for year of passing var chkmobileno = /^[0-9,\- ]*$/; //var chkemailid = /^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/ ; var chkemailid = /^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/; var ck_password = /^[A-Za-z0-9!@#$%^&*()_]{6,20}$/; var chkrollno = /^[a-zA-Z0-9\-]*$/; var chkappno = /^[0-9]*$/; var cname = theform.cname.value; var mname = theform.mname.value; var dob = theform.pwddob.value; var mobileno = theform.pwdmobile.value; var appno = theform.appno.value; var errors = []; if ((!chkminlength(cname, 3)) || (!chkmaxlength(cname, 50)) || (!chkalpha.test(cname))) { errors[errors.length] = "Candidate Name."; } if ((!chkminlength(mname, 3)) || (!chkmaxlength(mname, 50)) || (!chkalphadot.test(mname))) { errors[errors.length] = "Mother's Name."; } if (!isDate(dob)) { // DOB errors[errors.length] = "Date of Birth."; } if ((!chkminlength(mobileno, 10)) || (!chkmaxlength(mobileno, 11))) { errors[errors.length] = "Mobile No."; } if ((!chkminlength(appno, 1)) || (!chkmaxlength(appno, 10)) || (!chkappno.test(appno))) { errors[errors.length] = "Registration No."; } if (errors.length > 0) { reportErrors(errors); return false; } else { return true; } } // validate function END //////////// =============== end RECOVER PASS VALIDATION =================== //////////// =============== CANDIDATE UPDATE INFO FORM VALIDATION =================== function validateprofupdate(theform) { //validate function var chkalpha = /^[A-Za-z ]+$/; var chkalphadot = /^[A-Za-z\. ]+$/; var chknumbers = /^\d{4}$/; // 4 used for year of passing var chkmobileno = /^[0-9,\- ]*$/; //var chkemailid = /^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/ ; var chkemailid = /^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/; var chknumbersmarks = /^\d{1,5}$/; var chkpinnumbers = /^[0-9]{1,6}$/; var cname = theform.cname.value; var fname = theform.fname.value; var mname = theform.mname.value; var dob = theform.dob.value; var nationality = theform.nationality.value; var caddrs = theform.caddrs.value; var ccity = theform.ccity.value; var cdist = theform.cdist.value; var cstate = theform.cstate.value; var cpin = theform.cpin.value; var chkpaddrs = theform.chkpaddrs; var mobileno = theform.mobileno.value; var emailid = theform.emailid.value; var errors = []; if ((!chkminlength(cname, 3)) || (!chkmaxlength(cname, 50)) || (!chkalpha.test(cname))) { errors[errors.length] = "Candidate Name."; } if ((!chkminlength(fname, 3)) || (!chkmaxlength(fname, 50)) || (!chkalphadot.test(fname))) { errors[errors.length] = "Father's Name."; } if ((!chkminlength(mname, 3)) || (!chkmaxlength(mname, 50)) || (!chkalphadot.test(mname))) { errors[errors.length] = "Mother's Name."; } if ((!chkminlength(ccity, 3)) || (!chkmaxlength(ccity, 80)) || (!chkalphadot.test(ccity))) { errors[errors.length] = "Correspondence Address(City)."; } if ((!chkminlength(cdist, 2)) || (!chkmaxlength(cdist, 80)) || (!chkalphadot.test(cdist))) { errors[errors.length] = "Correspondence Address(Dist.)."; } if (cstate < 1) { errors[errors.length] = "Correspondence Address(State)."; } if (!chkpinnumbers.test(cpin)) { errors[errors.length] = "Correspondence Address(Pincode)."; } if (!chkblankdata(emailid)) { // check only if user has entered some data if ((!chkminlength(emailid, 8)) || (!chkmaxlength(emailid, 130)) || (!chkemailid.test(emailid))) { errors[errors.length] = "Email id."; } } if (!chkblankdata(mobileno)) { // check only if user has entered some data if ((!chkminlength(mobileno, 6)) || (!chkmaxlength(mobileno, 50)) || (!chkmobileno.test(mobileno))) { errors[errors.length] = "Phone No./Mobile No."; } } if (!isDate(dob)) { // DOB errors[errors.length] = "Date of Birth."; } if ((!theform.gender[0].checked) && (!theform.gender[1].checked) ) { errors[errors.length] = "Gender."; } if ((!chkminlength(nationality, 1)) || (!chkmaxlength(nationality, 50)) ) { errors[errors.length] = "Nationality."; } if (errors.length > 0) { reportErrors(errors); return false; } else { //////////// return false; return true; } } // validate function END //////////// =============== end CANDIDATE UPDATE INFO FORM VALIDATION =================== //////////// =============== REGISTRATION FORM VALIDATION =================== function validatereg(theform) { //validate function var chkalpha = /^[A-Za-z ]+$/; var chkalphadot = /^[A-Za-z\. ]+$/; var chknumbers = /^\d{4}$/; // var chkmobileno = /^[0-9,\- ]*$/; //var chkemailid = /^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/ ; var chkemailid = /^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/; var ck_password = /^[A-Za-z0-9!@#$%^&*()_]{6,20}$/; var chknumbersmarks = /^\d{1,5}$/; var chkrollno = /^[a-zA-Z0-9\-]*$/; var chkpinnumbers = /^\d{6}$/; var cname = theform.cname.value; var fname = theform.fname.value; var mname = theform.mname.value; var dob = theform.dob.value; var mobileno = theform.mobileno.value; var emailid = theform.emailid.value; var catcode = theform.catcode.value ; var subcatcode1 = theform.subcatcode1.value ; var subcatcode2 = theform.subcatcode2.value ; var subcatcode3 = theform.subcatcode3.value ; var subcatcode4 = theform.subcatcode4.value ; var errors = []; if ((!chkminlength(cname, 3)) || (!chkmaxlength(cname, 50)) || (!chkalpha.test(cname))) { errors[errors.length] = "Candidate Name."; } if ((!chkminlength(fname, 3)) || (!chkmaxlength(fname, 50)) || (!chkalphadot.test(fname))) { errors[errors.length] = "Father's Name."; } if ((!chkminlength(mname, 3)) || (!chkmaxlength(mname, 50)) || (!chkalphadot.test(mname))) { errors[errors.length] = "Mother's Name."; } if (!chkblankdata(emailid)) { if ((!chkminlength(emailid, 8)) || (!chkmaxlength(emailid, 130)) || (!chkemailid.test(emailid))) { errors[errors.length] = "Email id."; } } if (!chkblankdata(mobileno)) { if ((!chkminlength(mobileno, 6)) || (!chkmaxlength(mobileno, 50)) || (!chkmobileno.test(mobileno))) { errors[errors.length] = "Phone No./Mobile No."; } } if (!chkminmaxval(catcode, 1, 5)) { errors[errors.length] = "Category."; } if ( (!chkminmaxval(subcatcode1, 0,2)) || (!chkminmaxval(subcatcode2, 0,3)) || (!chkminmaxval(subcatcode3, 0,2)) || (!chkminmaxval(subcatcode4,0,2)) ) { errors[errors.length] = "Sub-Category."; } if (!isDate(dob)) { // DOB errors[errors.length] = "Date of Birth."; } if (errors.length > 0) { reportErrors(errors); return false; } else { //////////// return false; return true; } } // validate function END //////////// =============== end REGISTRATION FORM VALIDATION =================== //////////// =============== CHANGE PASSWORD VALIDATION =================== function validatePassword(pw, options) { // default options (allows any password) var o = { lower: 0, upper: 0, alpha: 0, /* lower + upper */ numeric: 0, special: 0, length: [0, Infinity], custom: [ /* regexes and/or functions */ ], badWords: [], badSequenceLength: 0, noQwertySequences: false, noSequential: false }; for (var property in options) { o[property] = options[property]; } var re = { lower: /[a-z]/g, upper: /[A-Z]/g, alpha: /[A-Z]/gi, numeric: /[0-9]/g, special: /[^*@#!$]/g }, rule, i; // enforce min/max length if (pw.length < o.length[0] || pw.length > o.length[1]) return false; // enforce lower/upper/alpha/numeric/special rules for (rule in re) { if ((pw.match(re[rule]) || []).length < o[rule]) { return false; } } // enforce word ban (case insensitive) for (i = 0; i < o.badWords.length; i++) { if (pw.toLowerCase().indexOf(o.badWords[i].toLowerCase()) > -1) { return false; } } // enforce the no sequential, identical characters rule if (o.noSequential && /([\S\s])\1/.test(pw)) { return false; } // enforce alphanumeric/qwerty sequence ban rules if (o.badSequenceLength) { var lower = "abcdefghijklmnopqrstuvwxyz", upper = lower.toUpperCase(), numbers = "0123456789", qwerty = "qwertyuiopasdfghjklzxcvbnm", start = o.badSequenceLength - 1, seq = "_" + pw.slice(0, start); for (i = start; i < pw.length; i++) { seq = seq.slice(1) + pw.charAt(i); if ( lower.indexOf(seq) > -1 || upper.indexOf(seq) > -1 || numbers.indexOf(seq) > -1 || (o.noQwertySequences && qwerty.indexOf(seq) > -1) ) { //alert("retunr4"); return false; } } } // enforce custom regex/function rules for (i = 0; i < o.custom.length; i++) { rule = o.custom[i]; if (rule instanceof RegExp) { if (!rule.test(pw)) return false; } else if (rule instanceof Function) { if (!rule(pw)) return false; } } // great success! return true; } //////////// =============== end CHANGE PASSWORD VALIDATION =================== //////////// =============== UPLOAD PHOTOGRAPH VALIDATION =================== function photovalidate(theform) { // validate function var photograph = theform.photograph.value; if (!chkminlength(photograph, 1)) { alert("Select Photograph."); theform.photograph.focus(); return false; } var filext = ""; // get file extension var filename = photograph.toLowerCase(); filext = filename.lastIndexOf('.jpg'); if (filext == -1) { filext = filename.lastIndexOf('.jpeg') ; if (filext == -1) { filext = filename.lastIndexOf('.gif') ; if (filext == -1) { filext = filename.lastIndexOf('.png') ; if (filext == -1) { alert("Upload Only jpg/jpeg/gif/png File."); theform.photograph.focus(); return false; } } } } // if (chkimagesize(photograph) == false) { // return false; // } return true; } // validate function end //////////// ============= UPLOAD PHOTOGRAPH VALIDATION end ================= //////////// =============== GENERAL FUNCTIONS =================== function reportErrors(errors){ var msg = "Please Enter Valid Data for:"; for (var i = 0; i < errors.length; i++) { var numError = i + 1; msg += "\n" + numError + ". " + errors[i]; } alert(msg); return false; } function chkminlength(chkstr, minlen){ chkstr= trim(chkstr); if (chkstr.length < minlen) return false; else return true; } function chkmaxlength(chkstr, maxlen){ chkstr= trim(chkstr); if (chkstr.length > maxlen) return false; else return true; } function chkminmax(chkstr, minlen, maxlen){ chkstr= trim(chkstr); if ((chkstr.length < minlen) || (chkstr.length > maxlen)) return false; else return true; } function chkminmaxval(chkstr, minval, maxval) { if (isInteger(chkstr)== false) return false; if ((chkstr < minval) || (chkstr > maxval)) return false; else return true; } // trim functions function trim(strtotrim) { return strtotrim.replace(/^\s+|\s+$/g,""); } function ltrim(strtotrim) { return strtotrim.replace(/^\s+/,""); } function rtrim(strtotrim) { return strtotrim.replace(/\s+$/,""); } // trim functions END function chkblankdata(chkstr){ chkstr= trim(chkstr); if (chkstr.length < 1) return true; else return false; } // check valid date of birth function isInteger(s){ var i; for (i = 0; i < s.length; i++){ // Check that current character is number. var c = s.charAt(i); if (((c < "0") || (c > "9"))) return false; } // All characters are numbers. return true; } function stripCharsInBag(s, bag){ var i; var returnString = ""; // Search through string's characters one by one. // If character is not in bag, append to returnString. for (i = 0; i < s.length; i++){ var c = s.charAt(i); if (bag.indexOf(c) == -1) returnString += c; } return returnString; } function daysInFebruary (year){ // February has 29 days in any year evenly divisible by four, // EXCEPT for centurial years which are not also divisible by 400. return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 ); } function DaysArray(n) { for (var i = 1; i <= n; i++) { this[i] = 31; if (i==4 || i==6 || i==9 || i==11) {this[i] = 30} if (i==2) {this[i] = 29} } return this } function isDate(dtStr){ var dtCh= "/"; var minYear= 1974; var maxYear= 2006; var daysInMonth = DaysArray(12); var pos1=dtStr.indexOf(dtCh); var pos2=dtStr.indexOf(dtCh,pos1+1); // var strMonth=dtStr.substring(0,pos1); // if format is mm/dd/yyyy // var strDay=dtStr.substring(pos1+1,pos2); // if format is mm/dd/yyyy var strDay=dtStr.substring(0,pos1); // if format is dd/mm/yyyy var strMonth=dtStr.substring(pos1+1,pos2); // if format is dd/mm/yyyy var strYear=dtStr.substring(pos2+1); var doberrs = ""; strYr=strYear; if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1); if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1); for (var i = 1; i <= 3; i++) { if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1); } month=parseInt(strMonth); day=parseInt(strDay); year=parseInt(strYr); /////alert(day + ' ' + month) ; if (pos1==-1 || pos2==-1){ // alert("The date format should be : mm/dd/yyyy") return false; } if (strMonth.length<1 || month<1 || month>12){ // alert("Please enter a valid month") return false; } if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){ // alert("Please enter a valid day") return false; } if (strYear.length != 4 || year==0 || year < minYear || year > maxYear){ // alert(minYear + ' ' + maxYear); // doberrs = "Date of Birth (enter year between "+minYear+" and "+maxYear+")" // alert("Warning! Enter a valid 4 digit year between "+minYear+" and "+maxYear); return false; } if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){ /// alert("Please enter a valid date") return false; } return true; } // check valid date of birth END function chkimagesize(imagesrc) { // function to check image height, width imgobj = new Image() ; imgobj.src = imagesrc ; alert(imgobj.height); if(imgobj.height > 350 ) { return false; } if(imgobj.width > 250 ) { return false; } return true; } // function to check image height, width END //////////// =============== end GENERAL FUNCTIONS ===================