js驗證密碼長度須在8到20位之間,並至少包含以下4種類型中的3種:英文大寫、英文小寫、數字及符號
也就是多幾個條件語句,程式碼如下:
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 "密碼必須含有特殊字元";
return true;
}
js驗證密碼長度須在8到20位之間,並至少包含以下4種類型中的3種:英文大寫、英文小寫、數字及符號
也就是多幾個條件語句,程式碼如下:
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;
}
}
}