Validating a url
See the URL Standard if you’re looking to parse URLs in the same way that browsers do. Assume that this regex will be used for a public URL shortener written in PHP, so URLs like shouldn’t pass (even though they’re technically valid). If you have a specialized scheme you'd like to have supported, let me know.I wanted to know if there is any standard APIs in Java to validate a given URL?
There appear to be some good examples on this thread PHP validation/regex for URL Then a preg_match against a good regular expression or filter_var php.net/manual/en/filter.filters.is your best bet.
I stumbled on this whilst searching SO for any questions about PHP URL validation that don't use it, because I've found it to be pretty much useless.
Regarding Gordon M's comment, have a look at the following gist, for an example of how PHP's FILTER_VALIDATE_URL probably doesn't work how you might expect it to: gist.github.com/anonymous/10967187 Appendix B.
There are a number of other URI validation modules out there as well (see below.) This one focuses on being fast, lightweight, and relatively 'real-world'. it's good if you want to check user input, and don't need to parse out the URI/URL into chunks.
Right now the module focuses on HTTP URIs, since they're arguably the most common.This validator checks the markup validity of Web documents in HTML, XHTML, SMIL, Math ML, etc.