1、身份证输入的地方
<label>身份证号:</label>
<input id="idcard" name="user.idcard" type="text"/>
<span id="idcardspan"></span>
2、js中做验证
$("#idcard").bind('blur',function(){
var idcard=$("#idcard").val();
if(idcard!="")
{
if(!checkIDCard(idcard))
{
idcardflag=false;
$("#idcardspan").css("color","#ff0000");
$("#idcardspan").html("请输入正确的身份证号码!");
}
else
{
$("#idcardspan").css("color","#43860c");
$("#idcardspan").html("正确");
}
}
});
3、checkIDCard ()
function checkIDCard (str)
{
var isIDCard1 = new Object();
var isIDCard2 = new Object();
isIDCard1=/^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/;
isIDCard2=/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[A-Z])$/;
if (isIDCard1.test(str)||isIDCard2.test(str))
{return true;}
return false;
}