免費論壇 繁體 | 簡體
Sclub交友聊天~加入聊天室當版主
分享
返回列表 回復 發帖

URL格式運用

  1. <script language="JavaScript">

  2. <!--

  3. function IsURL(str_url){

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

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

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

  7.    + "|" // allow IP和DOMAIN

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

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

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

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

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

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

  14. <!--

  15. function IsURL(str_url){

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

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

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

  19.    + "|" // allow IP和DOMAIN

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

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

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

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

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

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

  26.    var re=new RegExp(strRegex);

  27.    //re.test()

  28.    if (re.test(str_url)){

  29.       return (true);        //符合

  30.    }else{

  31.       return (false);      //不符合

  32.    }

  33. }


  34. function check(){

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

  36. }

  37. -->

  38. </script>




  39. 部份HTML︰


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

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

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

  43. </form>

複製代碼
執行畫面︰




返回列表