服务器 频道

ASP中正则表达式的应用

  四、示例

  1 、判断数字的正确性

  <%@ Language=VBScript %>

  <script language="javascript" runat="server">

  function isNumeric(strNumber) {

  return (strNumber.search(/^(-|+)?d+(.d+)?$/) != -1);

  }

  function isUnsignedNumeric(strNumber) {

  return (strNumber.search(/^d+(.d+)?$/) != -1);

  }

  function isInteger(strInteger) {

  return (strInteger.search(/^(-|+)?d+$/) != -1);

  }

  function isUnsignedInteger(strInteger) {

  return (strInteger.search(/^d+$/) != -1);

  }

  </script>

  <HTML>

  <BODY>

  <b>判断数字的正确性</b>

  <%

  Dim strTemp

  strTemp = CStr(Request.Form("inputstring"))

  If strTemp = "" Then strTemp = "0"

  %>

  <TABLE BORDER="1" CELLPADDING="4" CELLSPACING="2">

  <TR>

  <TD ALIGN="right"><B>原始字符串</B></TD>

  <TD><%= strTemp %></TD>

  </TR>

  <TR>

  <TD ALIGN="right"><B>数字</B></TD>

  <TD><%=isNumeric(strTemp)%></TD>

  </TR>

  <TR>

  <TD ALIGN="right"><B>非负数字</B></TD>

  <TD><%=isUnsignedNumeric(strTemp)%></TD>

  </TR>

  <TR>

  <TD ALIGN="right"><B>整数</B></TD>

  <TD><%=isInteger(strTemp)%></TD>

  </TR>

  <TR>

  <TD ALIGN="right"><B>非负整数()</B></TD>

  <TD><%=isUnsignedInteger(strTemp)%></TD>

  </TR>

  </TABLE>

  <FORM ACTION="<%=Request.ServerVariables("SCRIPT_NAME")%>" METHOD="post">

  请输入一个数字:<BR>

  <INPUT TYPE="text" NAME="inputstring" SIZE="50"></INPUT><BR>

  <INPUT TYPE="submit" Value="提交"></INPUT><BR>

  </FORM>

  </BODY>

  </HTML>

  2、判断Email地址的正确性

  <%

  Function isemail(strng)

  isemail = false

  Dim regEx, Match

  Set regEx = New RegExp

  regEx.Pattern = "^w+((-w+)|(.w+))*@[A-Za-z0-9]+((.|-)[A-Za-z0-9]+)*.[A-Za-z0-9]+$"

  regEx.IgnoreCase = True

  Set Match = regEx.Execute(strng)

  if match.count then isemail= true

  End Function

  %>

  

0
相关文章