魚骨頭的雲端圖書館's Archiver

mhfo 發表於 2016-8-12 16:03

URL格式運用

[code]<script language="JavaScript">

<!--

function IsURL(str_url){

   var strRegex = "^((https|http|ftp|rtsp|mms)?://)"

   + "?(([0-9a-zA-Z_!~*'().&=+$%-]+: )?[0-9a-zA-Z_!~*'().&=+$%-]+@)?" //ftp的user@

   + "(([0-9]{1,3}.){3}[0-9]{1,3}" // IP URL- 123.123.123.123

   + "|" // allow IP和DOMAIN

   + "([0-9a-zA-Z_!~*'()-]+.)*" // DOMAIN- www.

   + "([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]." // second DOMAIN

   + "[a-z]{2,6})" // first level domain- .com or .museum

   + "(:[0-9]{1,4})?" // port- :80

   + "((/?)|" // a slash isn't required if there is no file name

   + "(/[0-9a-zA-Z_!~*'().;?&=+$,%#-]+)+/?)[code]<script language="JavaScript">

<!--

function IsURL(str_url){

   var strRegex = "^((https|http|ftp|rtsp|mms)?://)"

   + "?(([0-9a-zA-Z_!~*'().&=+$%-]+: )?[0-9a-zA-Z_!~*'().&=+$%-]+@)?" //ftp的user@

   + "(([0-9]{1,3}.){3}[0-9]{1,3}" // IP URL- 123.123.123.123

   + "|" // allow IP和DOMAIN

   + "([0-9a-zA-Z_!~*'()-]+.)*" // DOMAIN- www.

   + "([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]." // second DOMAIN

   + "[a-z]{2,6})" // first level domain- .com or .museum

   + "(:[0-9]{1,4})?" // port- :80

   + "((/?)|" // a slash isn't required if there is no file name

   + "(/[0-9a-zA-Z_!~*'().;?:@&=+$,%#-]+)+/?)[        DISCUZ_CODE_0        ]quot;;

   var re=new RegExp(strRegex);

   //re.test()

   if (re.test(str_url)){

      return (true);        //符合

   }else{

      return (false);      //不符合

   }

}


function check(){

alert(IsURL(document.form1.urls.value));

}

-->

</script>




部份HTML︰


<form id="form1" name="form1" method="post" action="">

  <input name="urls" type="text" />

  <input type="button" name="Submit" value="檢查"  onclick="check();"/>

</form>

[/code][color=#d7282b][size=12pt]執行畫面︰[/size][/color]
[img]http://9.blog.xuite.net/9/6/a/b/15799520/blog_2086784/txt/133512443/0.jpg[/img]

[img]http://9.blog.xuite.net/9/6/a/b/15799520/blog_2086784/txt/133512443/2.jpg[/img]

[img]http://9.blog.xuite.net/9/6/a/b/15799520/blog_2086784/txt/133512443/3.jpg[/img]

頁: [1]

Powered by Discuz! Archiver 7.0.0  © 2001-2009 Comsenz Inc.