I'm looking to validate an URL. I have already a script that validates to not allow www.
and http://
but i need to also validate for .co.uk
.com
etc.
My script won't run if they enter something like example.co.ukff
.
I have this for a full URL:
^[a-zA-Z]+[:\/\/]+[A-Za-z0-9\-_]+\\.+[A-Za-z0-9\.\/%&=\?\-_]+$/i
I just need to validate the end .co.uk
or .com
etc.
Far from pretending this to be the ideal regex to match urls, the particular problem of only matching urls which do not begin with www can be resolved with a negative lookahead :
(?!www\.)
meaning that the following text should not be www.Therefore, your regex adapted with this negative lookahead:
^(?!www\.)[A-Za-z0-9_-]+\.+[A-Za-z0-9.\/%&=\?_:;-]+$
matches the following urls
but not those:
Try This...
/^http:\/\/|(www\.)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/
It's working exactly what you want.
it takes with or with out
http://, https://,
andwww
.