My application is perfoming "domain name to ip" and "ip to domain name" resolving.
To reduce request overwok would be useful to check domain name correctness before sending request right in application. To avoid user mistakes in typing domain name.

So we can write a C++ function to check if string is a real domain name or it is a simple string with abracadabra:

BOOL isValidDomainName(wchar_t* dName);
function takes Unicode string and return true; if it contains correct domain name, like or return false; if it not.

How we can implement simple checkup?
Let me think. Valid domain name is differ from ordinary string:

1. domain name can't start with '-' sign
2. domain name can contains only 'a-z' characters, '0-9' digits, and '-' sign.
(No special or control characters).
3. domain name ends with TLD part like .com, .net, .org, .name, .museum and etc.
4. domain name can be multi level like (

I was trying to write my own version of isValidDomainName() but it did not works (

PHP Code:
BOOL isValidDomainName(wchar_tdName)
wchar_tpNULL//Context pointer to next token

wszTLD=wcstok_s(dName_T("."), &p); 
wszTLD==NULL && wcscmp(dName,_T("localhost"))!=NULL) return false// no dots and no localhost string
        do {
wszTLD=wcstok_s(NULL_T("."), &p);            
wcscmp(wszTLD,_T("com"))) return true;
            else return 
false// there are dots but no com TLD string found
// domain can't start with '-' sign
if(dName[0]=='-')return false;

P.S. it's C++ code, not php. Simply I could not find tag for C++ code. Tag for better visual perception.
Maybe your version of this function will be more successful and effective. Any ideas?