<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<script>
function check(){
//if (j==0) Xb2="男"
// else Xb2="女"
//var Jmsfzh1=Jmsfzh+i;
var Xb2="男";
var Jmsfzh1="Jmsfzh1";
alert(trim(document.all(Jmsfzh1).value));
if (trim(document.all(Jmsfzh1).value)==""){
alert("请输入人员的居民身份证号!");
document.all(Jmsfzh1).focus();
return;
}
else
{
if (Jmsfzhjy(trim(document.all(Jmsfzh1).value),Xb2)=="error1"){
alert("您输入的身份证号不是数字信息!");
document.all(Jmsfzh1).focus();
return;
}
if (Jmsfzhjy(trim(document.all(Jmsfzh1).value),Xb2)=="error2"){
alert("您输入的身份证号位数不正确!");
document.all(Jmsfzh1).focus();
return;
}
if (Jmsfzhjy(trim(document.all(Jmsfzh1).value),Xb2)=="error3"){
alert("您输入的身份证号年份不正确!");
document.all(Jmsfzh1).focus();
return;
}
if (Jmsfzhjy(trim(document.all(Jmsfzh1).value),Xb2)=="error4"){
alert("您输入的身份证号日期不正确!");
document.all(Jmsfzh1).focus();
return;
}
if (Jmsfzhjy(trim(document.all(Jmsfzh1).value),Xb2)=="error5"){
alert("您输入的身份证号性别信息不正确!");
document.all(Jmsfzh1).focus();
return;
}
}
alert("ok");
}
//判断居民身份证号输入是否正确1218
function Jmsfzhjy(strsfzh,xb)
{
var cd=strsfzh.length;
var year=-1;
var month=-1;
var day=-1;
for (kk=0;kk<cd;kk++){
if (strsfzh.charAt(kk)>"9" || strsfzh.charAt(kk)<"0"){
h1="error1";
return h1;
}
}
if (cd!=15&&cd!=18){
h1="error2";
return h1
}
if (cd==15){
s1=strsfzh.substring(0,6);
s2="19"+strsfzh.substring(6,15)+"0";
strsfzh=s1+s2;
}
year=issfzhYearValid(parseInt(strsfzh.substring(6,10)));
if (year==-1){
h1="error3"
return h1
}
month=parseInt(strsfzh.substring(10,12));
day=isDayValid(year,month,parseInt(strsfzh.substring(12,14)));
if (day=="-1"){
h1="error4"
return h1
}
s=strsfzh.substring(16,17);
if ((s%2==0&&xb=="男")||(s%2==1&&xb=="女")){
h1="error5"
return h1
}
}
//判断居民身份证号年份的合法性
function issfzhYearValid(year){
var retyear=year;
if (year==0 || year<1900 ||year>2100) retyear=-1;
return retyear;
}
//判断日期和月份的合法性
function isDayValid(year,month,day){
var retday=day;
if (day<1||day>31||month<1||month>12){
retday=-1;
}
else {
if (day==31&&(month==2||month==4||month==6||month==9||month==11)){
retday=-1;
}
else {
if(month==2&&day>28&&!(day==29&&year%4==0&&(year%100!==0||year%400==0))){
retday=-1
}
}
}
return retday;
}
function trim(string) {
var temp = "";
var temp1="";
string = '' + string;
splitstring = string.split(" ");
for(i = 0; i < splitstring.length; i++)
temp1 += splitstring[i];
splitstring = temp1.split("?");
for(i = 0; i < splitstring.length; i++)
temp += splitstring[i];
return temp;
}
</script>
<body>
<select id="xingbie1" >
<option value="-1">-请选择-</option>
<option value="男">男</option>
<option value="女">女</option>
</select>
<input name="Jmsfzh1" id="Jmsfzh1" type="text" value="">
<input value="检查" type="button" onClick="check()">
</body>
</html>