Table of Contents

Class Validator

Namespace
NuvTools.Validation.Brazil
Assembly
NuvTools.Validation.dll

Provides validation methods for Brazilian document numbers and identification formats.

public static class Validator
Inheritance
Validator
Inherited Members

Methods

IsCNPJ(string)

Validates a Brazilian CNPJ (Cadastro Nacional da Pessoa Jurídica) number using the official checksum algorithm. Accepts both formatted (XX.XXX.XXX/XXXX-XX) and unformatted (XXXXXXXXXXXXXX) input. Supports the new RFB alphanumeric format (uppercase A–Z and 0–9 in positions 1–12, numeric check digits in 13–14) while remaining backward compatible with the legacy numeric-only format.

public static bool IsCNPJ(this string value)

Parameters

value string

The CNPJ value to validate.

Returns

bool

True if the CNPJ is valid according to the checksum algorithm; otherwise, false.

Examples

bool isValid = "12.345.678/0001-95".IsCNPJ();
bool isValidUnformatted = "12345678000195".IsCNPJ();
bool isValidAlphanumeric = "12.ABC.345/01DE-35".IsCNPJ();

IsCPF(string)

Validates a Brazilian CPF (Cadastro de Pessoas Físicas) number using the official checksum algorithm. Accepts both formatted (XXX.XXX.XXX-XX) and unformatted (XXXXXXXXXXX) input.

public static bool IsCPF(this string value)

Parameters

value string

The CPF value to validate.

Returns

bool

True if the CPF is valid according to the checksum algorithm; otherwise, false.

Examples

bool isValid = "123.456.789-01".IsCPF();
bool isValidUnformatted = "12345678901".IsCPF();

IsCPForCNPJ(string)

Validates a CPF or CNPJ by automatically detecting the document type based on length. Accepts both formatted and unformatted input.

public static bool IsCPForCNPJ(this string value)

Parameters

value string

The CPF or CNPJ value to validate (11 digits for CPF, 14 digits for CNPJ).

Returns

bool

True if the value is a valid CPF or CNPJ; otherwise, false.

Examples

bool isValid1 = "123.456.789-01".IsCPForCNPJ(); // Validates as CPF
bool isValid2 = "12.345.678/0001-95".IsCPForCNPJ(); // Validates as CNPJ

IsMobileNumber(string)

Validates a Brazilian mobile phone number. The method checks if the phone number contains a valid Brazilian area code (DDD), followed by the digit 9 and then exactly eight digits (format: XX 9 XXXX-XXXX).

public static bool IsMobileNumber(this string mobileNumber)

Parameters

mobileNumber string

The mobile number to validate (accepts formatted or unformatted input).

Returns

bool

True if the mobile number is valid; otherwise, false.

Examples

bool isValid = "11987654321".IsMobileNumber(); // São Paulo mobile
bool isValid2 = "(21) 98765-4321".IsMobileNumber(); // Rio de Janeiro mobile

IsZipCodeNumber(string)

Validates a Brazilian ZIP code (CEP - Código de Endereçamento Postal). Accepts formats: XXXXX-XXX or XXXXXXXX (with or without hyphen).

public static bool IsZipCodeNumber(this string zipCode)

Parameters

zipCode string

The ZIP code to validate.

Returns

bool

True if the ZIP code format is valid; otherwise, false.

Examples

bool isValid = "01310-100".IsZipCodeNumber(); // With hyphen
bool isValid2 = "01310100".IsZipCodeNumber(); // Without hyphen