正则判断 输入数据是否正确
//正则验证手机号码格式
function checkregtel(regtel){
var str=regtel;
var Expression=/^13(\d{9})$|^15(\d{9})$/;
var objExp=new RegExp(Expression);
if(objExp.test(str)==true){
return true;
}else{
return false;
}
}
//验证座机号码格式
function checkregtels(tegtels){
var str=regtels;
var Expression=/^(\d{3}-)(\d{8})$|^(\d{4}-)(\d{7})$|^(\d{4}-)(\d{8})$/;
var objExp=new RegExp(Expression);
if(objExp.test(str)==true){
return true;
}else{
return false;
}
}
//验证电子邮件格式
function checkregemail(emails){
var str=emails;
var Expression=/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
var objExp=new RegExp(Expression);
if(objExp.test(str)==true){
return true;
}else{
return false;
}
}
//对表单中用户提交的数据进行判断
function cherkginfo(form,mark){
//判断邮件数据
if(mark==4||mark=='all'){
if(form.email.value==""){
chknew_email.innerHTML="email is emtey";
form.email.style.backgroundColor="#FF0000";
return false;
}else if(!checkregemail(form.email.value)){//调用自定义函数判断邮件
chknew_email.innerHTML="email address is not true";
form.email.style.backgroundColor="#FF0000";
return false;
}else{
chknew_email.innerHTML="";
form.email.style.backgroundColor="#FFFFFF";
}
}
// 判断电话号码数据
if(mark==5||mark=='all'){
if(form.mtel.value==""){
mtel.innerHTML="mtel is emtey";
form.mtel.style.backgroundColor="#FF0000";
return false;
}else if(!checkregmtel(form.email.value)){//调用自定义函数判断电话
chknew_mtel.innerHTML="mtel address is not true";
form.mtel.style.backgroundColor="#FF0000";
return false;
}else if(isNAN(form.mtel.value)){//isNAN判断是否为数字,是,返回FALSE,否返回 truel
chknew_mtel.interHTML="tel is must number"
form.mtel.style.backgroundColor="#FF0000";
return false;
}else{
chknew_mtel.innerHTML="";
form.mtel.style.backgroundColor="#FFFFFF";
}
}
}