Class Format
- Namespace
- NuvTools.Validation.Brazil
- Assembly
- NuvTools.Validation.dll
Provides formatting utilities for Brazilian document numbers.
public static class Format
- Inheritance
-
Format
- Inherited Members
Methods
FormatCNPJ(string)
Formats a CNPJ string into the standard Brazilian format: XX.XXX.XXX/XXXX-XX. Accepts both legacy numeric and the new RFB alphanumeric (uppercase A–Z and 0–9) representations. Separators in the input are stripped; lowercase letters are normalized to uppercase.
public static string FormatCNPJ(this string cnpj)
Parameters
cnpjstringThe CNPJ number as a string (14 alphanumeric characters, with or without separators).
Returns
- string
The formatted CNPJ string.
Examples
string formatted = "12345678000195".FormatCNPJ();
// Returns: "12.345.678/0001-95"
string alphanumeric = "12ABC34501DE35".FormatCNPJ();
// Returns: "12.ABC.345/01DE-35"
Exceptions
- ArgumentNullException
Thrown when
cnpjis null.- FormatException
Thrown when the input does not contain exactly 14 alphanumeric characters.
FormatCPF(string)
Formats a CPF string into the standard Brazilian format: XXX.XXX.XXX-XX
public static string FormatCPF(this string cpf)
Parameters
cpfstringThe CPF number as a string (digits only).
Returns
- string
The formatted CPF string.
Examples
string formatted = "12345678901".FormatCPF();
// Returns: "123.456.789-01"