asp.net旅行
//校验是否全由数字组成
![](/Images/OutliningIndicators/None.gif)
functionisDigit(s)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
![](/Images/OutliningIndicators/InBlock.gif)
varpatrn=/^[0-9]{1,20}$/;
![](/Images/OutliningIndicators/InBlock.gif)
if(!patrn.exec(s))returnfalse
![](/Images/OutliningIndicators/InBlock.gif)
returntrue
![](/Images/OutliningIndicators/InBlock.gif)
}
![](/Images/OutliningIndicators/None.gif)
//校验登录名:只能输入5-20个以字母开头、可带数字、“_”、“.”的字串
![](/Images/OutliningIndicators/None.gif)
functionisRegisterUserName(s)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
![](/Images/OutliningIndicators/InBlock.gif)
varpatrn=/^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$/;
![](/Images/OutliningIndicators/InBlock.gif)
if(!patrn.exec(s))returnfalse
![](/Images/OutliningIndicators/InBlock.gif)
returntrue
![](/Images/OutliningIndicators/InBlock.gif)
}
![](/Images/OutliningIndicators/None.gif)
//校验用户姓名:只能输入1-30个以字母开头的字串
![](/Images/OutliningIndicators/None.gif)
functionisTrueName(s)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
![](/Images/OutliningIndicators/InBlock.gif)
varpatrn=/^[a-zA-Z]{1,30}$/;
![](/Images/OutliningIndicators/InBlock.gif)
if(!patrn.exec(s))returnfalse
![](/Images/OutliningIndicators/InBlock.gif)
returntrue
![](/Images/OutliningIndicators/InBlock.gif)
}
![](/Images/OutliningIndicators/None.gif)
//校验密码:只能输入6-20个字母、数字、下划线
![](/Images/OutliningIndicators/None.gif)
functionisPasswd(s)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
![](/Images/OutliningIndicators/InBlock.gif)
varpatrn=/^(\w){6,20}$/;
![](/Images/OutliningIndicators/InBlock.gif)
if(!patrn.exec(s))returnfalse
![](/Images/OutliningIndicators/InBlock.gif)
returntrue
![](/Images/OutliningIndicators/InBlock.gif)
}
![](/Images/OutliningIndicators/None.gif)
//校验普通电话、传真号码:可以“+”开头,除数字外,可含有“-”
![](/Images/OutliningIndicators/None.gif)
functionisTel(s)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
![](/Images/OutliningIndicators/InBlock.gif)
//varpatrn=/^[+]{0,1}(\d){1,3}[]?([-]?(\d){1,12})+$/;
![](/Images/OutliningIndicators/InBlock.gif)
varpatrn=/^[+]{0,1}(\d){1,3}[]?([-]?((\d)|[]){1,12})+$/;
![](/Images/OutliningIndicators/InBlock.gif)
if(!patrn.exec(s))returnfalse
![](/Images/OutliningIndicators/InBlock.gif)
returntrue
![](/Images/OutliningIndicators/InBlock.gif)
}
![](/Images/OutliningIndicators/None.gif)
//校验手机号码:必须以数字开头,除数字外,可含有“-”
![](/Images/OutliningIndicators/None.gif)
functionisMobil(s)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
![](/Images/OutliningIndicators/InBlock.gif)
varpatrn=/^[+]{0,1}(\d){1,3}[]?([-]?((\d)|[]){1,12})+$/;
![](/Images/OutliningIndicators/InBlock.gif)
if(!patrn.exec(s))returnfalse
![](/Images/OutliningIndicators/InBlock.gif)
returntrue
![](/Images/OutliningIndicators/InBlock.gif)
}
![](/Images/OutliningIndicators/None.gif)
//校验邮政编码
![](/Images/OutliningIndicators/None.gif)
functionisPostalCode(s)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
![](/Images/OutliningIndicators/InBlock.gif)
//varpatrn=/^[a-zA-Z0-9]{3,12}$/;
![](/Images/OutliningIndicators/InBlock.gif)
varpatrn=/^[a-zA-Z0-9]{3,12}$/;
![](/Images/OutliningIndicators/InBlock.gif)
if(!patrn.exec(s))returnfalse
![](/Images/OutliningIndicators/InBlock.gif)
returntrue
![](/Images/OutliningIndicators/InBlock.gif)
}
![](/Images/OutliningIndicators/None.gif)
//校验搜索关键字
![](/Images/OutliningIndicators/None.gif)
functionisSearch(s)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
varpatrn=/^[^`~!@#$%^&*()+=|\\\][\]\{\}:;''\,.<>/?]
{1}[^`~!@$%^&()+=|\\\][\]\
{\}:;''\,.<>?]
{0,19}$/;
![](/Images/OutliningIndicators/InBlock.gif)
if(!patrn.exec(s))returnfalse
![](/Images/OutliningIndicators/InBlock.gif)
returntrue
![](/Images/OutliningIndicators/InBlock.gif)
}
![](/Images/OutliningIndicators/None.gif)
functionisIP(s)//byzergling
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
![](/Images/OutliningIndicators/InBlock.gif)
varpatrn=/^[0-9.]{1,20}$/;
![](/Images/OutliningIndicators/InBlock.gif)
if(!patrn.exec(s))returnfalse
![](/Images/OutliningIndicators/InBlock.gif)
returntrue
![](/Images/OutliningIndicators/InBlock.gif)
}
![](/Images/OutliningIndicators/None.gif)
正则表达式
![](/Images/OutliningIndicators/None.gif)
"^\\d+$" //非负整数(正整数+0)
![](/Images/OutliningIndicators/None.gif)
"^[0-9]*[1-9][0-9]*$" //正整数
![](/Images/OutliningIndicators/None.gif)
"^((-\\d+)|(0+))$" //非正整数(负整数+0)
![](/Images/OutliningIndicators/None.gif)
"^-[0-9]*[1-9][0-9]*$" //负整数
![](/Images/OutliningIndicators/None.gif)
"^-?\\d+$" //整数
![](/Images/OutliningIndicators/None.gif)
"^\\d+(\\.\\d+)?$" //非负浮点数(正浮点数+0)
![](/Images/OutliningIndicators/None.gif)
"^(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*))$" //正浮点数
![](/Images/OutliningIndicators/None.gif)
"^((-\\d+(\\.\\d+)?)|(0+(\\.0+)?))$" //非正浮点数(负浮点数+0)
![](/Images/OutliningIndicators/None.gif)
"^(-(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*)))$" //负浮点数
![](/Images/OutliningIndicators/None.gif)
"^(-?\\d+)(\\.\\d+)?$" //浮点数
![](/Images/OutliningIndicators/None.gif)
"^[A-Za-z]+$" //由26个英文字母组成的字符串
![](/Images/OutliningIndicators/None.gif)
"^[A-Z]+$" //由26个英文字母的大写组成的字符串
![](/Images/OutliningIndicators/None.gif)
"^[a-z]+$" //由26个英文字母的小写组成的字符串
![](/Images/OutliningIndicators/None.gif)
"^[A-Za-z0-9]+$" //由数字和26个英文字母组成的字符串
![](/Images/OutliningIndicators/None.gif)
"^\\w+$" //由数字、26个英文字母或者下划线组成的字符串
![](/Images/OutliningIndicators/None.gif)
"^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$" //email地址
![](/Images/OutliningIndicators/None.gif)
"^[a-zA-z]+://(\\w+(-\\w+)*)(\\.(\\w+(-\\w+)*))*(\\?\\S*)?$" //url
![](/Images/OutliningIndicators/None.gif)
"^[A-Za-z0-9_]*$"
![](/Images/OutliningIndicators/None.gif)