Loading...

使用javascript 正規化判斷網址url是否正確

Temperature: 0 °C

Mark ChangMark Chang
author_tools

使用javascript判斷網址url是否正確

正規化方式如下:

 var str = URL;
//判斷網址的正規化表示方式:http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
var Expression = /http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/;
var objExp = new RegExp(Expression);
if (objExp.test(str) == true) {
return true;//如果正確
} else {
return false;//如果不正確
}

 

#故事  #判斷網址url是否正確  #javascript  
https://innstory.com/story-使用javascript_正規化判斷網址url是否正確-2888
javascript

Prev
 使用_Closure_Compiler_幫_javascript_瘦身

Next
使用手機將網址分享到_Line時如何強制使用預設外部瀏覽器開啟 

About the Author

Mark Chang

離不開電腦的宅男

Visitor message

Leave some footprints to prove that you visited me

Recommended reading

Author's other related stories

分享 連刪掉的前男友帳號,臉書都幫你存好好?他教你打開臉書個人資料庫,裡面個資多到嚇死人-風傳媒

分享 連刪掉的前男友帳號,臉...

看到這篇文章,突然覺得好笑又有趣,試想這些網站平台不紀錄你的個資那要紀錄什麼,這本來就是他們的商業模...

分享 涉貪想落跑?門都沒有!馬來西亞前總理納吉遭限制出境,印尼「度假」計畫泡湯-風傳媒

分享 涉貪想落跑?門都沒有!...

看起來退任元首接受調查然後移至監牢真的不分國界,覺得以後直接在元首辦公處旁蓋一座監牢比較快,然後退任...

分享 499之亂》員工倒在最前線?中華電信子公司宏華國際:加班費加倍發給-風傳媒

分享 499之亂》員工倒在最...

我其實很想知道身邊的朋友到底有多少人去排了XD

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format