Regular expression for URL validation in javascript [duplicate]
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
精彩评论