Versão em português: LEIAME.md
Maoli is a C# helper library for common Brazilian business rules (CEP, CPF and CNPJ), compatible with .NET Framework 4.6+, .NET Core 1.0+, and .NET 5+.
Currently implements:
- CEP validation
- CPF validation
- CNPJ validation
For client-side validation of CPF and CNPJ, please see Maoli.js.
Cep.Validate(string value)
- checks if a string value is a valid CEP representation. Returns true if CEP string is valid; false otherwise.
if (Cep.Validate("99999-999"))
{
Console.WriteLine("CEP is valid");
}
Cpf.Validate(string value)
- checks if a string value is a valid CPF representation. Returns true if CPF string is valid; false otherwise.
if (Cpf.Validate("999.999.99-99"))
{
Console.WriteLine("CPF is valid");
}
Cpf.Complete(string value)
- completes a partial CPF string by appending a valid checksum trailing.
Returns a CPF string with a valid checksum trailing.
// outputs "99999999999"
var cpf = Cpf.Complete("99999999"));
Cnpj.Validate(string value)
- checks if a string value is a valid CNPJ representation. Returns true if CNPJ string is valid; false otherwise.
if (Cnpj.Validate("99.999.999/9999-99"))
{
Console.WriteLine("CPNJ is valid");
}
Cnpj.Complete(string value)
- completes a partial CNPJ string by appending a valid checksum trailing.
Returns a CNPJ string with a valid checksum trailing.
// outputs "99999999999999"
var cnpj = Cnpj.Complete("999999999999"));
NumberSpeller.Spell(int value)
- returns the number spelled in Brazilian Portuguese.
The maximum value is int.MaxValue
.
var speller = new NumberSpeller();
var number = speller.Spell(2022);
// outputs "dois mil duzentos e vinte e dois"
Console.WriteLine(number);
NumberSpeller.Spell(long value)
- returns the number spelled in Brazilian Portuguese.
The maximum value is long.MaxValue
.
var speller = new NumberSpeller();
var number = speller.Spell(2022L);
// outputs "dois mil duzentos e vinte e dois"
Console.WriteLine(number);
To install Maoli using NuGet, run the following command in the Package Manager Console:
Install-Package Maoli
See the NuGet website.
The following .NET Fiddles are available to test Maoli:
- CPF validation: https://dotnetfiddle.net/7h7X00
- CNPJ validation: https://dotnetfiddle.net/IpEEmC
Source code is available at GitHub.
This project is licensed under the MIT License.
Adriano Ueda @adriueda