|
|
// check the result generallyvar ip = new RegExp(/^0[^71]|^11|^10|^19|^18|^17|120/);var noVal = "";// message for noticevar msgMap = {"^0":" 请输入原有密码","^11":" 新密码复杂度不够","^10":" 新密码过短","^17":" 请输入新密码","^19":" 新密码过长","^18":" 新密码包括非法字符","120":" 密码重复错误"};// find the input textvar pMap = {"^0":"pw2","^11":"pw0","^10":"pw0","^17":"pw0","^19":"pw0","^18":"pw0","120":"pw1"};// initiatefunction initP(){$("#modPwd").click(function(){var display = $("#inputPwd").css("display");$("#inputPwd").css("display",display =="none"?"":"none");});$("input[type='submit']").click(function(){return sC();//submit check});iC();//input check}//check for submitfunction sC(){var ps = getApw();var r = aop(ps[2])+""+checkPass(ps[0])+""+arp(ps[0],ps[1]);//if (aop(ps[2]) == 1 && (ps[0] == noVal || ps[1] == noVal)) {alert("请输入新密码");return false;}//alert(r);if (r.match(ip)){for(var k in msgMap){if (r.match(k)){alert(msgMap[k]);try{$("#"+pMap[k]).select();return false;break;}catch (e){}}}} }// get all passwordfunction getApw(){var ps = new Array();$("input[id^='pw']").each(function(e){var i = this.id.replace('pw','');ps[i] = this.value;});return ps;}// check for inputfunction iC(){var n = document.createElement("span");//create the element for notice$(n).css({color:'red'});$("input[id^='pw']").keyup(function(){var ps = getApw();var r = aop(ps[2])+""+checkPass(ps[0])+""+arp(ps[0],ps[1]);//alert(r);if (r.match(ip)){for(var k in msgMap){if (r.match(k)){n.innerText = msgMap[k];$("#"+pMap[k]).after(n);// display the noticebreak;}}} else { n.innerText = "";}});}// check the repeat passwordfunction arp(np,rp){if (np == rp) return 1;else return 0;}// check the old passwordfunction aop(op){if (op == noVal)return 0;else return 1;}// clean all password input textfunction clean(){var ps = getApw();for (var i = 0;i < ps.length ;i++ ){ps[i].value="";}} html文件中的form表单
<form id="pw"> ORIGINAL PASSWORD:<input type="text" id="pw0"/> <br><br> NEW PASSWORD:<input type="text" id="pw1"/> <br><br> REPEAT PASSWORD:<input type="text" id="pw2"/> <br><br> <input type="submit" value="submit"/> </form> 此篇文章仍为原创,上一次的密码验证在使用中出现了不少问题,所以进行了重写,这回的代码和上次相比略有清爽感,绝的作为程序员代码重构还是很重要的,希望能有读者给予评论,哈哈。 |
|