如何判断URL格式是否符合规范?

来源:asp之家 时间:2010-01-12 20:14:00 

 asp判断网址格式是否合法代码

 具体实现办法见下列代码:

<%
 function checkisUrl(tmpString)
      dim c,i
      checkisUrl = true
      tmpString=Lcase(trim(tmpString))
      if left(tmpString,7)<>"http://" then tmpString="http://"&tmpString
      for i = 8 to Len(checkisUrl)
            c = Lcase(Mid(tmpString, i, 1))
            if InStr("abcdefghijklmnopqrstuvwxyz_-./\", c) <= 0 and not IsNumeric(c) then
                  checkisUrl = false
                  exit function
            end if
      next
      if Left(tmpString, 1) = "." or Right(tmpString, 1) = "." then
            checkisUrl = false
            exit function
      end if
      if InStr(tmpString, ".") <= 0 then
            checkisUrl = false
            response.Write "f3"
            exit function
      end if
      if InStr(checkisUrl, "..") > 0 then
            checkisUrl = false
      end if
end function
%>
<%
if checkisUrl(request("u"))=true then
      %>恭喜,你的URL通过!
<%
else
      %>对不起,你的URL不合乎规范,请重新检查!
<%end if%>

当然还可以使用正则表达式来验证网址合法性,代码更简洁。

标签:url,格式,网址,验证
0
投稿

猜你喜欢

  • ASP页面内VBScript和JScript的交互

    2007-09-11 13:49:00
  • 动态程序防采集的新方法

    2010-04-24 15:24:00
  • 使用DIV+CSS设计网页的好处

    2007-10-14 15:02:00
  • Oracle关于时间/日期的操作

    2009-02-26 10:37:00
  • 像聪明女孩穿衣服那样设计网页文字

    2007-11-06 16:45:00
  • 获得当前数据库对象依赖关系的实用算法

    2009-01-08 13:28:00
  • css元素层叠级别及z-index剖析

    2008-08-29 12:41:00
  • javascript图片预加载

    2009-08-30 12:47:00
  • ASP分页技术详解

    2007-08-13 15:25:00
  • 把网页中的电话号码生成图片的ASP程序

    2008-11-07 16:12:00
  • SQL SERVER数据库开发之触发器的应用

    2008-06-23 13:09:00
  • asp如何自动反馈电子邮件?

    2002-01-01 06:54:00
  • 美之鉴 – 女人与Web设计

    2009-12-09 15:36:00
  • SQLServer 连接 EXCEL

    2009-07-09 19:00:00
  • Atlas—微软的Ajax工具包

    2007-09-07 09:52:00
  • 数据库中identity字段不必是系统产生的唯一值 性能优化方法(新招)

    2011-09-30 11:26:06
  • 解决oracle用户连接失败的解决方法

    2011-01-04 19:35:00
  • MySQL中的字符串模式匹配

    2010-03-09 16:30:00
  • 理解和使用Oracle 8i分析工具LogMiner

    2010-07-16 13:22:00
  • Access函数大全

    2009-12-23 19:22:00
  • asp之家 网络编程 m.aspxhome.com