//4.4 字符串替换函数.Replace();
/**********************4字符类验证******************************/
/**********************5浏览器类******************************/
//5.1 判断浏览器的类型
function getIEType()
{
return window.navigator.appName;
}
//5.2 判断ie的版本
function getIEVersion()
{
return window.navigator.appVersion;
}
//5.3 判断客户端的分辨率
function getResolvingPower()
{
return window.screen.height+"*"+window.screen.width;
}
/**********************5浏览器类******************************/
/**********************6综合类******************************/
//6.1 email的判断。
function isMail(mail)
{
return(new RegExp(/^/w+((-/w+)|(/./w+))*/@[A-Za-z0-9]+((/.|-)[A-Za-z0-9]+)*/.[A-Za-z0-9]+$/).test(mail));
}
//6.2 手机号码的验证
function isCellPhoneNum(num)
{
if(isNaN(num))
{
alert("输入的不是数字!");
return false;
}
var len = num.length;
if(len!=11)
{
return false;
}
return true;
}
//6.3 身份证的验证
function isIdCardNo(num)
{
if(isNaN(num))
{
alert("输入的不是数字!");
return false;
}
var len = num.length;
if (len == 15)
re = new RegExp(/^(/d{6})()?(/d{2})(/d{2})(/d{2})(/d{3})$/);
else if(len == 18)
re = new RegExp(/^(/d{6})()?(/d{4})(/d{2})(/d{2})(/d{3})(/d)$/);
else
{
alert("输入的数字位数不对!");
return false;
}
var a = num.match(re);
if (a != null)
{
if (len==15)
{
var D = new Date("19"+a[3]+"/"+a[4]+"/"+a[5]);
var B = D.getYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5];
}
else
{
var D = new Date(a[3]+"/"+a[4]+"/"+a[5]);
var B = D.getFullYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5];
}
if (!B)
{
alert("输入的身份证号 "+ a[0] +" 里出生日期不对!");
return false;
}
}
return true;
}
//身份证严格验证
function IdCardNoCheck(sId){
var aCity={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"}
var iSum=0
var info=""
if(!/^/d{17}(/d|x)$/i.test(sId))
return false;
sId=sId.replace(/x$/i,"a");
if(aCity[parseInt(sId.substr(0,2))]==null)return "Error:非法地区";
sBirthday=sId.substr(6,4)+"-"+Number(sId.substr(10,2))+"-"+Number(sId.substr(12,2));
var d=new Date(sBirthday.replace(/-/g,"/"))
if(sBirthday!=(d.getFullYear()+"-"+ (d.getMonth()+1) + "-" + d.getDate()))return "Error:非法生日";
for(var i = 17;i>=0;i --) iSum += (Math.pow(2,i) % 11) * parseInt(sId.charAt(17 - i),11)
if(iSum%11!=1)return "Error:非法证号";
//aCity[parseInt(sId.substr(0,2))]+","+sBirthday+","+(sId.substr(16,1)%2?"男":"女")
return true;
}
//6.4电话号码的验证
function PhoneCheck(str){
var reg=/(^[0-9]{3,4}/-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^/([0-9]{3,4}/)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/
alert(reg.test(str));
}
//6.5验证IP地址
function isip(s){
var check=function(v){try{return (v<=255 && v>=0)}catch(x){return false}};
var re=s.split(".")
return (re.length==4)?(check(re[0]) && check(re[1]) && check(re[2]) && check(re[3])):false
}
/**********************6综合类******************************/
//回车键换为tab
function enterToTab()
{
if(event.srcElement.type != 'button' && event.srcElement.type != 'textarea'
&& event.keyCode == 13)
{
event.keyCode = 9;
}
}
//具有在输入非数字字符不回显的效果,即对非数字字符的输入不作反应。
function numbersonly(field,event){
var key,keychar;
if(window.event){
key = window.event.keyCode;
}
else if (event){
key = event.which;
}
else{
return true ;
}
keychar = String.fromCharCode(key);
if((key == null)||(key == 0)||(key == 8)||(key == 9)||(key == 13)||(key == 27)){
return true;
}
else if(("0123456789.").indexOf(keychar)>-1){
window.status = "";
return true;
}
else {
window.status = "Field excepts numbers only";
return false;
}
}
//
function txtOnKeyPress()
{
var code=String.fromCharCode(window.event.keyCode)+'';
alert(code);
var temp =eval("isInt('"+code+"')");
window.event.returnValue = temp;
}
|