1、身份证验证(带x) //验证身份证信息(获取出生日期和性别) function func_CheckSFZ(ob) { var obj = ob.value; obj = obj.toUpperCase(); if (!(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(obj))) { alert(‘输入的身份证号长度不对,或者号码不符合规定!\n15位号码应全为数字,18位号码末位可以为数字或X。‘); return false; } var gre = /^(\d{6})(\d{2})([01]\d)([0123]\d)(\d{3})$/; var reg = /^(\d{6})(18|19|20)?(\d{2})([01]\d)([0123]\d)(\d{3})([0-9]|X)$/; var csny = document.getElementById("txt_CSRQ").value; var XB = document.getElementById("sel_XB").value; if(obj.value != "") { if(obj.length == 15 || obj.length == 18) { if(obj.length == 15) { if(gre.test(obj)) { var year = obj.charAt(6)+obj.charAt(7); if(parseInt(year) < 10) { year = "20"+ year; } else { year = "19"+ year; } var month = obj.substring(8,10); var day = obj.substring(10,12); csny = year+"-"+month+"-"+day; if(parseInt(obj.charAt(14)/2)*2 != obj.charAt(14)) XB ="男"; else XB = "女"; } else { alert("提示:身份证格式不正确!"); return false; } } else if(obj.length == 18) { if(reg.test(obj)) { var year = obj.substring(6,10); var month = obj.substring(10,12); var day = obj.substring(12,14); csny = year+"-"+month+"-"+day; if(parseInt(obj.charAt(16)/2)*2 != obj.charAt(16)) XB ="男"; else XB = "女"; } else { alert("提示:身份证格式不正确!"); return false; } } document.getElementById("txt_CSRQ").value = csny; document.getElementById("sel_XB").value = XB; } else { alert("提示:身份证为15位或者18位!"); return false; } } return true; } 2、验证金额: /^-?((\d{1,3}(,\d{3})*?)|\d+)(\.\d{1,2})?$/
时间: 2024-11-07 00:28:06