//验证邮箱:
function ss(){
var isEmail1 = /^\w+([\.\-]\w+)*\@\w+([\.\-]\w+)*\.\w+$/;
var isEmail2 = /^.*@[^_]*$/;
var addr = document.getElementById("tt").value;
if (!isEmail1.test(addr) || !isEmail2.test(addr)){
alert("fail");
}else{
alert("success");
}
}
<input type=text id=tt>
<input type=button value=checkit onclick="ss()">
//验证身份证,包括18位,最后一个是X的
//身份证验证函数
function isIdCardNo(obj)
{
var powers=new Array("7","9","10","5","8","4","2","1","6","3","7","9","10","5","8","4","2");
var parityBit=new Array("1","0","X","9","8","7","6","5","4","3","2");
var sex="1";
var _id=obj;
//alert(_id);
if(_id=="") return false;
var _valid=false;
//-------------------------------
//校验18位的身份证号码
if(_id.length==18){
_id=_id+"";
var _num=_id.substr(0,17);
var _parityBit=_id.substr(17);
var _power=0;
for(var i=0;i< 17;i++){
//校验每一位的合法性
if(_num.charAt(i)<'0'||_num.charAt(i)>'9'){
return false;
break;
}else{
//加权
_power+=parseInt(_num.charAt(i))*parseInt(powers[i]);
//设置性别
if(i==16&&parseInt(_num.charAt(i))%2==0)
sex="0";
else
sex="1";
}
}
//取模
var mod=parseInt(_power)%11;
if(parityBit[mod]==_parityBit)
return true;
else
return false;
}else{
//-------------------------------
//校验15位的身份证号码
_id=_id+"";
for(var i=0;i<_id.length;i++){
//校验每一位的合法性
if(_id.charAt(i)<'0'||_id.charAt(i)>'9'){
return false;
break;
}
}
var year=_id.substr(6,2);
var month=_id.substr(8,2);
var day=_id.substr(10,2);
var sexBit=_id.substr(14);
//校验年份位
if(year<'01'||year >'90') return false;
//校验月份
if(month<'01'||month >'12') return false;
//校验日
if(day<'01'||day >'31') return false;
//设置性别
if(sexBit%2==0)
sex="0";
else
sex="1";
return true;
}
}
//验证是否包含字母的
function check()
{
var reg=/[A-Za-z]+/g;
var input=document.getElementById("txt").value;
var m=reg.test(input)
if(m==false)alert("OK");
if(m==true)alert("不能有字母");
}
posted on 2008-05-29 15:02
bcterry 阅读(105)
评论(0) 编辑 收藏