I want to validate url started with http/https/www/ftp
and checks for /\
slashes and checks for .com
,.org
etc at the end of URL using regular expression. Is there any regex patttern for URL validation?
We can use java. net. url class to validate a URL. The idea is to create a URL object from the specified String representation.
@:%_\+~#= , to match the domain/sub domain name.
You can use the URLConstructor to check if a string is a valid URL. URLConstructor ( new URL(url) ) returns a newly created URL object defined by the URL parameters. A JavaScript TypeError exception is thrown if the given URL is not valid.
This works:
Pattern p = Pattern.compile("(@)?(href=')?(HREF=')?(HREF=\")?(href=\")?(http://)?[a-zA-Z_0-9\\-]+(\\.\\w[a-zA-Z_0-9\\-]+)+(/[#&\\n\\-=?\\+\\%/\\.\\w]+)?");
Matcher m = p.matcher("your url here");
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