I'm working on create a regular expression in javascript to validate website urls. I searched a bit in the stackoverflow community and i did not find something to be completed helpful.
My regex until now: /(https?:\/\/)?(www\.)?[a-zA-Z0-9]+\.[a-zA-Z]{2,}/g
But it seems to fail and pass the validation for the url with two w like ww.test.com
Should pass the test of regex:
http://www.test.com
https://www.test.com
www.test.com
www.test.co.uk
www.t.com
test.com
test.fr
test.co.uk
Should not pass the test of regex:
w.test.com
ww.test.com
www.test
test
ww.test.
.test
.test.com
.test.co.ul
.test.
Any suggestions or thoughts?