js常⽤证件类型的正则表达式
Js 常⽤证件类型的正则表达式
//居民户⼝簿
reg =/^[a-zA-Z0-9]{3,21}$/;
// 护照验证
reg =/^[a-zA-Z]{5,17}$ | [a-zA-Z0-9]{5,17}$/;
//军官证或⼠兵证
reg =/^[\u4E00-\u9FA5]{1,2}(字第)([0-9a-zA-Z]{4,8})(号?)$/;
//驾驶证
reg =/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}(\d|x|X)$/;
//港澳居民来往内地通⾏证
reg =/^[HMhm]{1}([0-9]{10}|[0-9]{8})$/;
//台湾居民来往内地通⾏证
reg =/^([0-9]{8}|[0-9]{10})$/;
//⾝份证判断
isCardID(sId){
var aCity ={11:"北京",12:"天津",13:"河北",14:"⼭西",15:"内蒙古",21:"辽宁",22:"吉林",23:"⿊龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",3 5:"福建",36:"江西",37:"⼭东",41:"河南",42:"湖北",43:"湖南",44:"⼴东",45:"⼴西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西" ,62:"⽢肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"⾹港",82:"澳门",91:"国外"
};js中文正则表达式
var iSum =0;
var info ="";
if(!(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(sId))){
return false;
}else im().length ==15){
var re =new RegExp(/^(\d{2})(\d{4})(\d{2})(\d{2})(\d{2})(\d{3})$/);
var arrSplit = sId.match(re);
if(aCity[parseInt(arrSplit[1])]==null){
return false;
}
//检查⽣⽇⽇期是否正确
var dtmBirth =new Date("19"+ arrSplit[3]+"/"+ arrSplit[4]+"/"+ arrSplit[5]);
var bGoodDay;
bGoodDay =(Year()==Number(arrSplit[3]))&&((Month()+1)==Number(arrSplit[4]))&&(Date()==Number( arrSplit[5]));
if(!bGoodDay){
return false;
}
return true;
}
if(!/^\d{17}(\d|x)$/i.test(sId))return"你输⼊的⾝份证长度或格式错误";
sId = place(/x$/i,"a");
if(aCity[parseInt(sId.substr(0,2))]==null)return"你的⾝份证地区⾮法";
var sBirthday = sId.substr(6,4)+"-"+Number(sId.substr(10,2))+"-"+Number(sId.substr(12,2));
var d =new place(/-/g,"/"));
if(sBirthday !=(d.getFullYear()+"-"+(d.getMonth()+1)+"-"+ d.getDate()))return"⾝份证上的出⽣⽇期⾮法";
for(var i =17; i >=0; i--) iSum +=(Math.pow(2, i)%11)*parseInt(sId.charAt(17- i),11);
if(iSum %11!=1)return"你输⼊的⾝份证号⾮法";
//aCity[parseInt(sId.substr(0,2))]+","+sBirthday+","+(sId.substr(16,1)%2?"男":"⼥");//此次还可以判断出输⼊的⾝份证号的⼈性别
return true;
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论