//校验是否全由数字组成
代码
- function isDigit(s)
- {
- var patrn=/^[0-9]{1,20}$/;
- if (!patrn.exec(s)) return false
- return true
- }
//校验登录名:只能输入5-20个以字母开头、可带数字、“_”、“.”的字串
代码
- function isRegisterUserName(s)
- {
- var patrn=/^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$/;
- if (!patrn.exec(s)) return false
- return true
- }
//校验用户姓名:只能输入1-30个以字母开头的字串
代码
- function isTrueName(s)
- {
- var patrn=/^[a-zA-Z]{1,30}$/;
- if (!patrn.exec(s)) return false
- return true
- }
- }}
-
-
- [code]
- function isPasswd(s)
- {
- var patrn=/^(\w){6,20}$/;
- if (!patrn.exec(s)) return false
- return true
- }
//校验普通电话、传真号码:可以“+”开头,除数字外,可含有“-”
代码
- function isTel(s)
- {
-
- var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
- if (!patrn.exec(s)) return false
- return true
- }
//校验手机号码:必须以数字开头,除数字外,可含有“-”
代码
- function isMobil(s)
- {
- var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
- if (!patrn.exec(s)) return false
- return true
- }
//校验邮政编码
代码
- function isPostalCode(s)
- {
-
- var patrn=/^[a-zA-Z0-9 ]{3,12}$/;
- if (!patrn.exec(s)) return false
- return true
- }
//校验搜索关键字
代码
- function isSearch(s)
- {
- var patrn=/^[^`~!@#$%^&*()+=|\\\][\]\{\}:;'\,.<>/?]{1}[^`~!@$%^&()+=|\\\]
- [\]\{\}:;'\,.<>?]{0,19}$/;
- if (!patrn.exec(s)) return false
- return true
- }
-
- function isIP(s)
- {
- var patrn=/^[0-9.]{1,20}$/;
- if (!patrn.exec(s)) return false
- return true
- }
正则表达式
代码
- "^\\d+$"
- "^[0-9]*[1-9][0-9]*$"
- "^((-\\d+)|(0+))$"
- "^-[0-9]*[1-9][0-9]*$"
- "^-?\\d+$"
- "^\\d+(\\.\\d+)?$"
- "^(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*))$"
-
- "^((-\\d+(\\.\\d+)?)|(0+(\\.0+)?))$"
- "^(-(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*)))$"
-
- "^(-?\\d+)(\\.\\d+)?$"
- "^[A-Za-z]+$"
- "^[A-Z]+$"
- "^[a-z]+$"
- "^[A-Za-z0-9]+$"
- "^\\w+$"
- "^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$"
- "^[a-zA-z]+://(\\w+(-\\w+)*)(\\.(\\w+(-\\w+)*))*(\\?\\S*)?$" //url
- "^[A-Za-z0-9_]*$"