0

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 only), like this:

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

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

Community
  • 1
  • 1
Nathan Campos
  • 28,769
  • 59
  • 194
  • 300

1 Answers1

1

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.

wilsonpage
  • 17,341
  • 23
  • 103
  • 147