var vcity={
21:”辽宁”,22:”吉林”,23:”黑龙江”,31:”上海”,32:”江苏”,
42:”湖北”,43:”湖南”,44:”广东”,45:”广西”,46:”海南”,50:”重庆”,
63:”青海”,64:”宁夏”,65:”新疆”,71:”台湾”,81:”香港”,82:”澳门”,91:”国外”
 

var checkCard = function(card)
var card = card;//card为用户输入的***号码
if(card === ”)
alert(‘请输入***号,***号不能为空’);
}
if(isCardNo(card) === false)
alert(‘您输入的***号码不正确,请重新输入’);
}
if(checkProvince(card) === false)
alert(‘您输入的***号码不正确,请重新输入’);
}
if(checkBirthday(card) === false)
alert(‘您输入的***号码生日不正确,请重新输入’);
}
if(checkParity(card) === false)
alert(‘您的***校验位不正确,请重新输入’);
}
return true;
//检查号码是否符合规范,包括长度,类型
{
var reg = /(^\\\\\\\\d{15}$)|(^\\\\\\\\d{17}(\\\\\\\\d|X)$)/;
{
return false;
return true;
 

var checkProvince = function(card)
var province = card.substr(0,2);
{
}
};

//检查生日是否正确
{
//***15位时,次序为省(3位)市(3位)年(2位)月(2位)日(2位)校验位(3位),皆为数字
{
var arr_data = card.match(re_fifteen);
var month = arr_data[3];
var birthday = new Date(’19′+year+’/’+month+’/’+day);
}
if(len == ’18′)
var re_eighteen = /^(\\\\\\\\d{6})(\\\\\\\\d{4})(\\\\\\\\d{2})(\\\\\\\\d{2})(\\\\\\\\d{3})([0-9]|X)$/;
var year = arr_data[2];
var day = arr_data[4];
return verifyBirthday(year,month,day,birthday);
return false;
 

var verifyBirthday = function(year,month,day,birthday)
var now = new Date();
//年月日是否合理
{
var time = now_year – year;
{
}
}
};

//校验位的检测
{
card = changeFivteenToEighteen(card);
if(len == ’18′)
var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
var cardTemp = 0, i, valnum;
{
}
if (valnum == card.substr(17, 1))
return true;
return false;
return false;
 

var changeFivteenToEighteen = function(card)
if(card.length == ’15′)
var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
var cardTemp = 0, i;
for(i = 0; i < 17; i ++)
cardTemp += card.substr(i, 1) * arrInt[i];
card += arrCh[cardTemp % 11];
}
};

文章标题:《JavaScript正则表达式验证***号码》 From Jeskitt  29th Sep,2015