0

I want to validate all type of url but few of my conditions are not working with the following regex:

^((https?|ftp|smtp|http):\/\/)?(www.)?[a-z0-9]+\.[a-z]+(\/[a-zA-Z0-9#]+\/?)*\.(com|in)$

It is not working with

  1. http://google.com
  2. https://google.com
  3. google.com
RalfFriedl
  • 1,134
  • 3
  • 11
  • 12
Puja
  • 1
  • 1

1 Answers1

0

If you look at your regex, you'll see that you require two dots (I added white spaces to identify them) in your url:

^((https?|ftp|smtp|http):\/\/)?(www.)?[a-z0-9]+   \.   [a-z]+(\/[a-zA-Z0-9#]+\/?)*   \.   (com|in)$

I recommend you to use https://regex101.com/ to check your regex.

But like George says, you can use commons regex for that purpose, instead of making a new one.


By the way, https? is catching https and http so that (https?|...|http)=(https?|...)

luckygulli
  • 21
  • 4