1

Possible Duplicate:
Validate email address in Javascript?
What is the best regular expression to check if a string is a valid URL?

I want to test that whether the string is url or not, right now I am stuck at this point. I am using this regex to validate my URL /(https|http):\/\/([_a-z\d\-]+(\.[_a-z\d\-]+)+)(([_a-z\d\-\\\.\/]+[_a-z\d\-\\\/])+)*/;

The problem with this regex is that it fails to validate this type of URL

http://www.abc/abc/

how to check that case.?

Community
  • 1
  • 1
Ajeet Pratap Maurya
  • 4,224
  • 3
  • 26
  • 44
  • See http://stackoverflow.com/questions/8667070/javascript-regular-expression-to-validate-url and http://stackoverflow.com/questions/1303872/trying-to-validate-url-using-javascript – Rohit Jain Oct 08 '12 at 13:37
  • 1
    duplicate of [this](http://stackoverflow.com/questions/1303872/trying-to-validate-url-using-javascript), [this](http://stackoverflow.com/questions/161738/what-is-the-best-regular-expression-to-check-if-a-string-is-a-valid-url), [this](http://stackoverflow.com/questions/833469/regular-expression-for-url?lq=1), [this](http://stackoverflow.com/questions/2102727/regular-expression-for-url?rq=1)... – jbabey Oct 08 '12 at 13:37
  • Just for the sake of simplicity, `\w` catches `[a-zA-Z0-9_]`. – inhan Oct 08 '12 at 13:39
  • I gone through the above links.. but my problem is that the regex i ma using is fine but if i remove .com or .in anything it also consider it a valid URL.. – Ajeet Pratap Maurya Oct 08 '12 at 13:40
  • Shouldn't it validate `http://site.com/abc/`, for example? – inhan Oct 08 '12 at 13:41
  • @inhan It validates `http://site.com/abc/` but if i do like this `http://www.site/abc/` it validates this.. how to invalidate that case – Ajeet Pratap Maurya Oct 08 '12 at 13:42
  • It's extremely hard to make the regex determine if it is valid unless you list the acceptable whole range of extensions in your regexp. There are so many unusual possibilities out there. You might want to stick with some tried solution out there. – inhan Oct 08 '12 at 13:50
  • @Ajeet Pratap Maurya : please check my new answer and validate it if you think it suits your needs. – Aelios Oct 09 '12 at 09:54

0 Answers0