<HTML>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<BODY>
<form action="http://www.baidu.com" οnsubmit="return toVaild()">
<input type="text" id="ff">
<input type="text" name="docNo" id="docNo" οnblur="isIdCardNo();" />
<input type="text" name="birthDate" id="birthDate" readonly="readonly" />
<input type="text" name="phoneNo" id="phoneNo" οnblur="checkMobile();" />
<input type="text" name="email" id="email" οnblur="checkEmail()" />
<input type="submit" id="submit" value ="提交"/>
</form>
</BODY>
<script language="javascript">
//增加身份证验证
function isIdCardNo() {
var num = $("#docNo").val();
var factorArr = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1);
var parityBit = new Array("1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2");
var varArray = new Array();
var intValue;
var lngProduct = 0;
var intCheckDigit;
var intStrLen = num.length;
var idNumber = num;
// initialize
if(intStrLen == 0){
return true;
}
if ((intStrLen != 15) && (intStrLen != 18)) {
$("#docNo").tips({
side:3,
msg:'请输入正确的身份证号',
bg:'#AE81FF',
time:2
});
$("#docNo").focus();
return false;
}
//通过身份证号获得出生年月
if($.trim($("#docNo").val()) != "") {
var date = "";
if($("#docNo").val().length == 15) {
date = '19'+$("#docNo").val().substr(6,2)+'-'+$("#docNo").val().substr(8,2)+'-'+$("#docNo").val().substr(10,2);
} else if ($("#docNo").val().length == 18) {
date = $("#docNo").val().substr(6,4)+'-'+$("#docNo").val().substr(10,2)+'-'+$("#docNo").val().substr(12,2);
}
$("#birthDate").val(date);
var now_time = new Date();
var birthday = new Date(date);
var newdate = now_time.getTime() - birthday.getTime();
var age = Math.ceil(newdate/1000/60/60/24/365);
if(age<18 ||age>65){
$("#docNo").tips({
side:3,
msg:'请重新输入身份证号,年龄不能小于18或大于65',
bg:'#AE81FF',
time:2
});
$("#docNo").focus();
return false;
}
}
return true;
}
//验证输入电话
function checkMobile(str){
var PHONE = $.trim($("#phoneNo").val());
var checkPhone=true;
var re= /(^1[3|5|8][0-9]{9}$)/;
if(PHONE == ""){
return true;
}
if(!re.test(PHONE)){
$("#phoneNo").tips({
side : 1,
msg : "请输入正确的手机号",
bg : '#FF5080',
time : 2
});
$("#phoneNo").focus();
return false;
}
return checkMobile;
}
//验证输入邮箱是否正确
function checkEmail(){
var str = $("#email").val();
var re=/\w+[@]{1}\w+[.]\w+/;
if(str == ""){
return true;
}
if(!re.test(str)){
$("#email").tips({
side:3,
msg:'请输入正确的邮箱',
bg:'#AE81FF',
time:2
});
$("#email").focus();
return false;
}
return true;
}
</script>
</HTML>