I want to have a regex that will validate url in following way
http://www.google.com ->valid url
www.google.com ->valid url
google.com ->in-valid url
http://google.com ->in-valid url
I have tried following regex from here
/(?:https?:\/\/)?(?:[a-zA-Z0-9.-]+?\.(?:[a-zA-Z])|\d+\.\d+\.\d+\.\d+)/
but it doens't validate the existence of www
www., but you include bits in your regex that allow for IPv4 addresses in the formhttp://0.0.0.0/? Did you just dump someone else's regex in your question in an attempt to make it look like you make some effort?