0

I have written a function that validates as string as a web url. Unfortunately, new top level domains like ".koeln" and ".cologne" and ".shop", etc are not yet supported using Patterns.WEB_URL.

Does anybody know how to add these domains or what should be done to make them update the Patterns class?

boolean validate(final String url){
    Pattern pattern = Patterns.WEB_URL;
    Matcher matcher = pattern.matcher(url);
    return matcher.matches();
}

Here is a list of all (?) TLDs including the new ones I am referring to:

List

Barthy
  • 3,151
  • 1
  • 25
  • 42

1 Answers1

1

Does anybody know how to add these domains

Write a regular expression. All Patterns is giving you is a canned set of regular expression Pattern objects. If you do not like those, create your own. You might use the existing WEB_URL implementation as a starting point.

Or, use java.net.URL to parse out the domain name (getHost()), then parse out the TLD, and do a lookup against a list of TLDs that you are interested in.

what should be done to make them update the Patterns class?

I would expect "them" to eventually deprecate WEB_URL, the way they have other aspects of Patterns.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thank you for your answer. I already thought of creating my own pattern. Do you know who, where and how I could bring up the topic so that Patterns.class may be updated? (Sorry for 'them', I of course meant the very smart people behind the entire Android OS.) – Barthy Mar 27 '15 at 23:51
  • 1
    @BarthyB.: You are certainly welcome to [file an issue](http://b.android.com). Bear in mind that even if they fixed it tomorrow, it will be years before most Android devices in use have it, and so you would still need to do something yourself as a workaround. You might poke around to see if somebody else already created the Java code for an updated TLD matcher. – CommonsWare Mar 27 '15 at 23:53