话不多说,请看代码

function IsHKID(str) {
 var strValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 // basic check length
 if (str.length < 8)
 return false;
 // handling bracket
 if (str.charAt(str.length-3) == '(' && str.charAt(str.length-1) == ')')
 str = str.substring(0, str.length - 3) + str.charAt(str.length -2);
 // convert to upper case
 str = str.toUpperCase();
 // regular expression to check pattern and split
 var hkidPat = /^([A-Z]{1,2})([0-9]{6})([A0-9])$/;
 var matchArray = str.match(hkidPat);
 // not match, return false
 if (matchArray == null)
 return false;
 // the character part, numeric part and check digit part
 var charPart = matchArray[1];
 var numPart = matchArray[2];
 var checkDigit = matchArray[3];
 // calculate the checksum for character part
 var checkSum = 0;
 if (charPart.length == 2) {
 checkSum += 9 * (10 + strValidChars.indexOf(charPart.charAt(0)));
 checkSum += 8 * (10 + strValidChars.indexOf(charPart.charAt(1)));
 } else {
 checkSum += 9 * 36;
 checkSum += 8 * (10 + strValidChars.indexOf(charPart));
 }
 // calculate the checksum for numeric part
 for (var i = 0, j = 7; i < numPart.length; i++, j--)
 checkSum += j * numPart.charAt(i);
 // verify the check digit
 var remaining = checkSum % 11;
 var verify = remaining == 0 "htmlcode">
function IsHKID(str) {
 var strValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 // basic check length
 if (str.length < 8)
 return false;
 // handling bracket
 if (str.charAt(str.length-3) == '(' && str.charAt(str.length-1) == ')')
 str = str.substring(0, str.length - 3) + str.charAt(str.length -2);
 // convert to upper case
 str = str.toUpperCase();
 // regular expression to check pattern and split
 var hkidPat = /^([A-Z]{1,2})([0-9]{6})([A0-9])$/;
 var matchArray = str.match(hkidPat);
 // not match, return false
 if (matchArray == null)
 return false;
 return true;
 }

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!

广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!