✘ Don’t check domain validity if you don’t need to. A lot of applications don’t need to constrain the domain field, so unless you have a compelling reason to constrain it, leave it open.
✘ Don’t check the length of a domain to determine validity. You can no longer assume domain endings
will be 2 or 3 characters long. They potentially can be between 1 and 63 characters long.
✔ Do use an IDN library to properly convert domain names if they are received in multiple formats. There are many libraries (a lot of them are free) that are used by major software vendors to implement this functionality. Make sure the library supports the most current (“IDNA2008”) standard, as the older standard introduces compatibility issues.
✘ Don’t use a hard-coded list of domains in your application. If you need to check if a domain exists, the best way to do it is using the DNS protocol. A live DNS query happens quickly and will provide your application with the most up-to-date data available.
✔ If you require a hard-coded list, do make sure it is regularly updated (e.g., daily) using an appropriate methodology. ICANN provides some sample toolkits on how this might be done.
✔ Do ask questions if you are not sure. ICANN is happy to help provide advice to software developers and implementers on what is needed. Contact us at: email@example.com.
✔ Do report websites or software that has problems accepting newer domains. If you notice a website that has problems, let us know and we’ll try to reach out to the operators to encourage them to follow these guidelines.
Sample toolkit - TLD verification tool
The primary method of correctly checking if a domain is valid is to use the DNS. If the application has access to the Internet (most applications do), the best way is simply to perform a DNS query. This ensures the most accurate and up-to-date data is returned from the most authoritative source – the DNS itself.
In some rare cases, it is not possible to use the DNS protocol. When software programs need to check whether a top-level domain is valid, but is not able to perform an online check, ICANN provides guidance on alternate methods. In particular, the program may need to use a regularly updated list of valid top-level domains to perform its checking. ICANN has put together sample programming code that software developers can use. The code is available under an open source license at: https://github.com/icann
Source : ICANN