开发者

Regular expression for URL validation in javascript [duplicate]

This question already has answers here: What is the best regular expression to check if a string is a valid URL? (62 answers) Closed 9 years ago.

I am having form which takes url as input..I want to validate it using javascript and regular expression..

it should accept

  • www.google.com
  • google.com
  • http://google.com

Please开发者_JS百科 suggest me a regular expression and total code if possible for validation of url... i tried lotta url given on many forums..but couldn't get appropriate answer.. thanks in advance


try this,

^(http\://)?[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$

this will support

  • http://google.com
  • http://www.google.com
  • www.google.com
  • google.com


You can test it easily with jQuery :

http://docs.jquery.com/Plugins/Validation/Methods/url.


try dis

url_reg = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;


This one would be fine, (http|https|)(://|)([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?

Try it here. works fine - http://www.regular-expressions.info/javascriptexample.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜