js姓名和身份證驗證

2021-08-07 06:21:21 字數 3321 閱讀 7911

jsp:
<

divclass="">

<

p>姓名

p>

<

inputtype="text"id="username"name="username"value="$"/>

div>

<

divclass="">

<

p>身份證號

p>

<

inputtype="text"id="idcard"name="idcard"value="$"/>

<

inputtype="button"name="submit"id="submit"value="提交資訊"class="">

js:
$(document).ready(function()

if(!/^[\u4e00-\u9fa5]$/.test(username))

if(cardid ==""|| cardid ==null)

if(!checkidcard(cardid))

}
});

// 身份證驗證

functioncheckidcard(num) $)|(^\d([0-9]|x)$)/.test(num)))

// 校驗位按照iso 7064:1983.mod 11-2的規定生成,x可以認為是數字10。

// 下面分別分析出生日期和校驗位

varlen, re;

len = num.length;

if(len == 15) )(\d)(\d)(\d)(\d)$/);

vararrsplit = num.match(re);

// 檢查生日日期是否正確

vardtmbirth =newdate('19'+ arrsplit[2] +'/'+ arrsplit[3] +'/'+ arrsplit[4]);

varbgoodday;

bgoodday = (dtmbirth.getyear() == number(arrsplit[2]))

&& ((dtmbirth.getmonth() + 1) == number(arrsplit[3]))

&& (dtmbirth.getdate() == number(arrsplit[4]));

if(!bgoodday)else

num += arrch[ntemp % 11];

return true;}}

if(len == 18) )(\d)(\d)(\d)(\d)([0-9]|x)$/);

vararrsplit = num.match(re);

// 檢查生日日期是否正確

vardtmbirth =newdate(arrsplit[2] +"/"+ arrsplit[3] +"/"+ arrsplit[4]);

varbgoodday;

bgoodday = (dtmbirth.getfullyear() == number(arrsplit[2]))

&& ((dtmbirth.getmonth() + 1) == number(arrsplit[3]))

&& (dtmbirth.getdate() == number(arrsplit[4]));

if(!bgoodday)else

valnum = arrch[ntemp % 11];

if(valnum != num.substr(17, 1))

return true;}}

return false;

}});

身份證驗證JS

function checkidcardstrict idcard var idcard idcard.touppercase var y,jym var s,m var idcard array new array element val idcard idcard array idcard.sp...

js 身份證驗證

function checkidcard idcard var idcard,y,jym var s,m var idcard array new array idcard array idcard.split 地區檢驗 if area parseint idcard.substr 0,2 null...

身份證驗證

1 簡單的正規表示式 1 preg match d d dx id card 2 preg match d 18 19 20 d 01 d 0123 d d d x id card 3 preg match d d d x x id card 2 複雜並且嚴格一些的驗證 這個可以驗證15位和18位的...