js_判斷當前url是否合法http(s)
阿新 • • 發佈:2018-04-17
sed gif false exp 判斷 har urn ssi function
1 alert(checkURL(‘http:555‘)); //false 2 function checkURL(URL) { 3 var str = URL, 4 Expression = /http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/, 5 objExp = new RegExp(Expression); 6 if(objExp.test(str) == true) { 7 return true 8 } else { 9 returnfalse 10 } 11 }
全部代碼:
1 <!DOCTYPE html> 2 <html> 3 4 <head> 5 <meta charset="UTF-8"> 6 <title></title> 7 </head> 8 9 <body> 10 <script type="text/javascript"> 11 alert(checkURL(‘http:555‘)); //View Codefalse 12 function checkURL(URL) { 13 var str = URL, 14 Expression = /http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/, 15 objExp = new RegExp(Expression); 16 if(objExp.test(str) == true) { 17 returntrue 18 } else { 19 return false 20 } 21 } 22 </script> 23 </body> 24 25 </html>
js_判斷當前url是否合法http(s)