Reputation: 2824
I am using following regex to test if url is valid...
var pattern = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
It returns true
for following urls...
http://google.com
http://google.co.uk
http://something.google.xyz
http://something.google.co.uk
But i want to allow plain domains as well for example...
google.com
google.nyc
google.co.uk
sub.google.com
Please help to modify this. Thanks
Upvotes: 1
Views: 702
Reputation:
If you only need to test that the URL is valid and aren't picking out specific parts you could use something simpler.
(https?:\/\/)?\w+\.
Upvotes: 1
Reputation: 1200
Try using this one, also applies for subdomains.
/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/
Upvotes: 0