javascript正则表达式检验汇总

/********************************************************************************* 

*abc.js

*javascript正则表达式检验

**********************************************************************************/

//校验是否全由数字组成

functionisDigit(s)

{

varpatrn=/^[0-9]{1,20}$/;

if(!patrn.exec(s))returnfalse

returntrue

}

//校验登录名:只能输入5-20个以字母开头、可带数字、“_”、“.”的字串

functionisRegisterUserName(s)

{

varpatrn=/^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$/;

if(!patrn.exec(s))returnfalse

returntrue

}

//校验用户姓名:只能输入1-30个以字母开头的字串

functionisTrueName(s)

{

varpatrn=/^[a-zA-Z]{1,30}$/;

if(!patrn.exec(s))returnfalse

returntrue

}

//校验密码:只能输入6-20个字母、数字、下划线

functionisPasswd(s)

{

varpatrn=/^(\w){6,20}$/;

if(!patrn.exec(s))returnfalse

returntrue

}

//校验普通电话、传真号码:可以“+”开头,除数字外,可含有“-”

functionisTel(s)

{

//varpatrn=/^[+]{0,1}(\d){1,3}[]?([-]?(\d){1,12})+$/;

varpatrn=/^[+]{0,1}(\d){1,3}[]?([-]?((\d)|[]){1,12})+$/;

if(!patrn.exec(s))returnfalse

returntrue

}

//校验手机号码:必须以数字开头,除数字外,可含有“-”

functionisMobil(s)

{

varpatrn=/^[+]{0,1}(\d){1,3}[]?([-]?((\d)|[]){1,12})+$/;

if(!patrn.exec(s))returnfalse

returntrue

}

//校验邮政编码

functionisPostalCode(s)

{

//varpatrn=/^[a-zA-Z0-9]{3,12}$/;

varpatrn=/^[a-zA-Z0-9]{3,12}$/;

if(!patrn.exec(s))returnfalse

returntrue

}

//校验搜索关键字

functionisSearch(s)

{

varpatrn=/^[^`~!@#$%^&*()+=|\\\][\]\{\}:;'\,.<>/?]{1}[^`~!@$%^&()+=|\\\][\]\{\}:;'\,.<>?]{0,19}$/;

if(!patrn.exec(s))returnfalse

returntrue

}

functionisIP(s)//byzergling

{

varpatrn=/^[0-9.]{1,20}$/;

if(!patrn.exec(s))returnfalse

returntrue

}

相关推荐