Commonly used regular expression records

(In order to copy directly in the future, write the method directly, ^_^)

1. Verify ID number

function isIdcard(idcard){
if(idcard == null || idcard.length !=18 !(/\d{17}[0-9X]/.text(idcard))){
 return false;
}
var factor = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2];
var random = "10X98765432";
var total = 0;
for (let i = 0; i < 17; i++){
 total += idcard.charAt(i) * factor[i];
}
return random[total % 11] == idcard.charAt(17);
}

2. Verify Chinese 2-15 digits

function isChinese() {
var reg = /^[\u4E00-\u9FA5]{2,15}$/;
return reg.test(xm);
}

 

Leave a hole and add it later...

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324934092&siteId=291194637