I'm trying to validate an url, basically this will be for a project where any kind of weird url could be possibly be introduced by the user, like for example:
- pickup.calendar.com/schedu/e-mail/pickup.php/123wec/99245t29-03882-4ttr-345nvnwikg3545/?
- mypage-services.info
- https://google.com
- http://mypersonaldomain.com.org
- mypersonaldomain2.com.org/services/123
- https%3A%2F%2Mycoolstuff.com
- wikipedia.org
- www.github.com
- https://testing.com/@myurl/about
I have tried using new URI(url) from java.net but it's not validating correctly, for values like +1.1234566 or just a number 123337000 or a word test it returns true but it shouldn't.
I have also tried the UrlValidator from apache-commons but an url like mypage-services.info says it's invalid.
Last thing i've tried is to use regex, this is what i've got so far:
^(http:\\/\\/|https:\\/\\/)?(www.)?([a-zA-Z0-9]+).[a-zA-Z0-9]*.[a-z]{3}.?([a-z]+)?$\n
But it's not working for url patterns like mypage-services.info
I know this seems already like a duplicate question but i have tried all of the regex i have found in similar questions and none of them have worked for my requirement.
To anybody who can provide me help on this i would appreciate it a lot, thank you.