I'm looking for a regex that accept urls like these:
http://www.example.com
www.example.com
This is what I have so far, but it regex doesn't match URLs without http://
or https://
, or ftp://
:
regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
How can I make the protocol optional?
Make the (ftp|http|https):\/\/
part optional:
((ftp|http|https):\/\/)?
Try this this will validate url with (http,ftp,https) or without(http,ftp,https)..
/^(?:(ftp|http|https):\/\/)?(?:[\w-]+\.)+[a-z]{3,6}$/;
Try this this will validate url with or without(http,ftp,https) in upper and lower cases and also allows you to for numerics
/^(?:(ftp|http|https)?:\/\/)?(?:[\w-]+\.)+([a-z]|[A-Z]|[0-9]){2,6}$/gi;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With