- <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>
-
複製代碼 執行畫面︰
|