p
網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、小程序制作、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了和靜免費(fèi)建站歡迎大家使用!
密碼input type="password" id=“pwd”
/p
驗證密碼就:
var pwd=docment.getElementById("pwd").value; //獲取密碼框里的元素
var reg="這里寫你要求密碼的正則表達(dá)式格式";
//例如密碼要求5-10位字母數(shù)字下劃線,那么正則式就是 var reg=/^\w{5,10}$/; (記住^開始和$不要漏了)
if(reg.test(pwd)){
return true;
)
只要用JavaScript判斷密碼輸入和密碼確認(rèn)輸入時候一致即可。
table
tr
td valign="middle"div align="right"密碼:/div/td
tddiv align="left"
input type="password" name="userpassword" id="userpassword" /span id="error_userpassword"/span/div/td
/tr
tr
td valign="middle"div align="right"密碼確認(rèn):/div/td
tddiv align="left"
input type="password" name="userpassword_enter" id="userpassword_enter" /span id="error_userpassword_enter"/span/div/td
/tr
/table
script language="javascript1.2"
function vertify_userpassword(){
if (document.getElementById("userpassword").value==""){
document.getElementById("error_userpassword").innerText="請輸入密碼!";return false;}
else
{document.getElementById("error_userpassword").innerText="";return true}
}
/script
用正則表達(dá)式吧
SCRIPT type="text/javascript"
function checkUserName(userName){
var reg = /^[a-z\d]{6,12}/; // 小寫字母
return reg.test(userName);
}
function checkPassword(userPassword){
var reg = /^\d{6}$/; // 數(shù)字
return reg.test(userPassword);
}
//alert(checkUserName('adf'));
//alert(checkPassword('1212122'))
/SCRIPT
JQUERY的用法:
var userStr=/^[A-Za-z0-9]{6,20}$/;
if(userStr.exec(loginname)==null){
alert("請輸入6-20位英文數(shù)字的登錄名");
$("#loginname").select();
}
input type="text" name="corpUserName" class="input" onblur="checkLoginName()" id="loginname"/
JS的用法:
function checkPass() {
var a=document.getElementById("password").value;
if(a.length 6 a.length16)
{alert("密碼太短了!!!");}
}
失去焦點(diǎn)的時候判斷一下 或者在提交的時候判斷一下就OK
//校驗密碼,校驗成功返回true,校驗失敗返回false
function?checkPassword(password){
var?numberCount,//數(shù)字字符數(shù)目
letterCount,//字母字符數(shù)目
numberRegExp?=?/[0-9]/,//數(shù)字正則
letterRegExp?=?/[a-z]/i,//字母正則,不區(qū)分大小寫
length?=?(password?=?password?||?'').length;
if(length??8){
return?false;
}
numberCount?=?letterCount?=?0;
for(var?i?=?0,?char;?i??length;?i++){
char?=?password.charAt(i);//取得每個字符
if(numberRegExp.test(char)){
numberCount?+=?1;//數(shù)字字符數(shù)目加1?
}else?if(letterRegExp.test(char)){
letterCount?+=?1;//字母字符數(shù)目加1?
}else{
return?false;//即不是字母又不數(shù)字,直接返回false
}???????
}
return?!(numberCount?==?length?||?letterCount?==?length);
}
另一優(yōu)化版本,完全不用正則
//校驗密碼,校驗成功返回true,校驗失敗返回false
function?checkPassword(password){
function?isNumber(charCode){
//48為字符'0'的unicode碼,57為字符'9'的unicode碼
return?charCode?=?48??charCode?=?57
}
function?isLetter(charCode){
//65為字符'A'的unicode碼,90為字符'Z'的unicode碼
//90為字符'a'的unicode碼,122為字符'z'的unicode碼
return?(charCode?=?65??charCode?=?90)?
||?(charCode?=?97??charCode?=?122);
}
var?numberCount,//數(shù)字字符數(shù)目
letterCount,//字母字符數(shù)目
length?=?(password?=?password?||?'').length;
if(length??8){
return?false;
}
numberCount?=?letterCount?=?0;
for(var?i?=?0,?charCode;?i??length;?i++){
charCode=?password.charCodeAt(i);//取得每個字符
if(isNumber(charCode)){
numberCount?+=?1;//數(shù)字字符數(shù)目加1?
}else?if(isLetter(charCode)){
letterCount?+=?1;//字母字符數(shù)目加1?
}else{
return?false;//即不是字母又不數(shù)字,直接返回false
}???????
}
return?!(numberCount?==?length?||?letterCount?==?length);
}
如果單純用正則的話,好難好難,我能力有限,實(shí)現(xiàn)不了,
本文題目:javascript密碼,js密碼加密解密
鏈接分享:http://chinadenli.net/article20/dsdeejo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)、外貿(mào)網(wǎng)站建設(shè)、定制網(wǎng)站、外貿(mào)建站、動態(tài)網(wǎng)站、App設(shè)計
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)