Identify a URL Using Regular Expressions [duplicate]
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.
精彩评论