JS 驗證密碼 不可為空,必須含有數字、字母、特殊字元,長度在8-12位

來源:互聯網
上載者:User

標籤:amp   char   length   other   密碼   asc   長度   bst   arc   

checkpassword = function(v){
var numasc = 0;
var charasc = 0;
var otherasc = 0;
if(0==v.length){
return "密碼不可為空";
}else if(v.length<8||v.length>12){
return "密碼至少8個字元,最多12個字元";
}else{
for (var i = 0; i < v.length; i++) {
var asciiNumber = v.substr(i, 1).charCodeAt();
if (asciiNumber >= 48 && asciiNumber <= 57) {
numasc += 1;
}
if ((asciiNumber >= 65 && asciiNumber <= 90)||(asciiNumber >= 97 && asciiNumber <= 122)) {
charasc += 1;
}
if ((asciiNumber >= 33 && asciiNumber <= 47)||(asciiNumber >= 58 && asciiNumber <= 64)||(asciiNumber >= 91 && asciiNumber <= 96)||(asciiNumber >= 123 && asciiNumber <= 126)) {
otherasc += 1;
}
}
if(0==numasc) {
return "密碼必須含有數字";
}else if(0==charasc){
return "密碼必須含有字母";
}else if(0==otherasc){
return "密碼必須含有特殊字元";
}else{
return true;
}
}
};

JS 驗證密碼 不可為空,必須含有數字、字母、特殊字元,長度在8-12位

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.