[][src]Crate validbr

Representation of Brazilian registries: CPF, CNPJ, RG, CNH, CEP and Credit Card Number.

validbr also provides validation for CPJ, CNPJ, CNH and Credit Card Number and a builtin database of brazilian CEP, Cities and States.

Cpf

Consist in 9 digits separated in partitions of 3 with . and two verifier digits separated by a - prefix, for example: 123.456.789-09.

Example of usage of CPF struct

use validbr::Cpf;
let cpf = Cpf::parse_str("123.456.789-09");
assert_eq!(cpf, Ok(Cpf { digits: [1, 2, 3, 4, 5, 6, 7, 8, 9], verifier_digits: [0, 9]}));

Supported formats

Cpf::parse_str only supports following formats:

  • ###.###.###-## (Commonly represented CPF)
  • ########### (Only digits CPF).

CNPJ

Consists in eight numbers separated by a . in partitions for 3 (except for the first two digits which are separated from the last two groups), a company branch number digit composed of four digits, separated by a prefix / and two last verifier digits prefixed with -, example: 12.345.678/0001-95.

Example of usage of CNPJ struct

use validbr::Cnpj;
let cpf = Cnpj::parse_str("12.345.678/0001-95");
assert_eq!(cpf, Ok(Cnpj { digits: [1, 2, 3, 4, 5, 6, 7, 8], branch_digits: [0, 0, 0, 1], verifier_digits: [9, 5]}));

Supported formats

Cnpj::parse_str only supports following formats:

  • ##.###.###/####-## (Commonly represented CNPJ)
  • ############## (Only digits CNPJ).

Features

Serde support

validbr supports serde serialization, which must be enabled with feature flag, for example:

[dependencies]
validbr = { version = "0.2", features = ["serde"] }

rand support

validbr also supports randomly generated CPF and CNPJ through rand crate, which must be enabled with feature flag, for example:

[dependencies]
validbr = { version = "0.2", features = ["rand"] }

Enable all

You could enable all features using complete flag:

[dependencies]
validbr = { version = "0.2", features = ["complete"] }

Modules

append

Array append utilities.

cnpj

Cnpj utility functions

cpf

Cpf utility functions

rg

RG utility functions

Macros

convert_to_u8

Converts every i32 in iterator $iter to a u8 value.

join_to_string

Converts each item of $expr to String and then join all them into a single String without any separator.

Structs

Cnpj

CNPJ consists of eight based digits, four digits for the branch (the number of the registered company) and two verifier digits.

Cpf

CPF consists of nine digits and two verifier digits.

Rg

RG does not have a standard for its format, so validbr uses String representing the RG code. Some emitters uses modulo 11 validation, others don't, some of them uses number only with verifier digit, others don't and includes Letters and special chars.

Enums

EmitterOrg

List of governmental organizations which emits Brazilian Registries.

UF

List of Brazilian Federative Units (Unidades Federativas).