seoppc
seoppc

Reputation: 2824

jquery domain and url validation

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

Answers (2)

user1184321
user1184321

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

JuniorDev
JuniorDev

Reputation: 1200

Try using this one, also applies for subdomains.

/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/

Upvotes: 0

Related Questions