JS验证姓名、邮箱、电话号码

<SCRIPTtype="text/javascript">

varredflag=0;

//姓名验证

functionisName(){

varname=$('#name').val();

if(name.search(/^[\u0391-\uFFE5\w]+$/)!=-1){

redflag=0;

returntrue;

}

else{

alert("姓名格式错误");

redflag=1;

returnfalse;

}

}

//邮箱验证

functionisEmail(){

varemail=$('#email').val();

if(email.search(/^([a-zA-Z0-9]+[_|_|.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|_|.]?)*[a-zA-Z0-9]+\.(?:com|cn)$/)!=-1){

//if(email.search(/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.+[c][o][m]$|[c][n]$/)!= -1){

//if(email.search(/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/)!= -1){

//if(email.search(/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/)!= -1){

//if(email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)!= -1){

redflag=0;

returntrue;

}

else{

alert("邮箱格式错误");

redflag=1;

returnfalse;

}

}

//验证电话号码

functionfucCheckTelPhone()

{

vartelphone=$('#telephone').val();

if(telphone.search(/^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/)!=-1){

redflag=0;

returntrue;

}

else{

alert("电话格式错误");

redflag=1;

returnfalse;

}

}

//验证手机号码

functionfucCheckTEL()

{

vartel=$('#tel').val();

if(tel.search(/^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/)!=-1){

redflag=0;

returntrue;

}

else{

alert("手机格式错误");

redflag=1;

returnfalse;

}

}

//验证QQ

functionisQQ()

{

varqq=$('#qq').val();

if(qq.search(/^[1-9]\d{4,8}$/)!=-1){

redflag=0;

returntrue;

}

else{

alert("qq格式错误");

redflag=1;

returnfalse;

}

}

//msn验证--(和邮箱的一样)

functionisMsn()

{

varmsn=$('#msn').val();

if(msn.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)!=-1){

redflag=0;

returntrue;

}

else{

alert("MSN格式错误");

redflag=1;

returnfalse;

}

}

//生日验证

functionisBirthDay()

{

varday=$('#birthday').val();

if(day.search(/\d{1,4}\-\d{1,2}\-\d{1,2}/)!=-1){

//varzzbds="(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)";

//if(day.search(zzbds)!= -1)

redflag=0;

returntrue;

}

else{

alert("生日格式错误");

redflag=1;

returnfalse;

}

}

functionnextStep(){

//if(redflag==0){

//  document.form0.submit();

//}else{

//  return ;

//}

if(isName()&&isBirthDay()&&isEmail()&&fucCheckTelPhone()&&fucCheckTEL()&&isQQ()&&isMsn()){

document.form0.submit();

}else{

return;

}

}

</SCRIPT>

上一篇:2018.08.28 洛谷P4556 [Vani有约会]雨天的尾巴(树上差分+线段树合并)


下一篇:Recon ASRC Conference