开发者

Identify a URL Using Regular Expressions [duplicate]

开发者 https://www.devze.com 2023-02-07 22:55 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicates: Checking for a valid url using Javascript Regular Expressions
This question already has answers here: Closed 12 years ago.

Possible Duplicates:

Checking for a valid url using Javascript Regular Expressions

PHP validation/regex for URL

I have a if statement that will check if the user entered a URL(HTTP Protocol onl开发者_运维知识库y), like this:

if(/^regexp/.test(url))

But how should be this regular expression to check if the text is a URL or not?


I believe this little function might help:

function isURL(string){
  regEx = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
  return regEx.test(string));
}

Let us know if it worked out!

W.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号