CEI
Cadastro Específico do INSS, the registration of employers without a CNPJ (construction works, rural producers), superseded by the CNO and the CAEPF.
Validate
- JavaScript library
- Python library
- Go library1 case fails
- Ruby library3 cases fail
- Rust library1 case fails
- .NET library4 cases fail
- Erlang library
Validates a CEI: 12 digits, 11 base digits and one check digit.
- The check digit weights the base by 7, 4, 1, 8, 5, 2, 1, 6, 3, 7, 4. It adds the tens of the sum to its units. Then it takes the complement to 10 of the resulting units digit (10 maps to 0).
- A value whose digits are all the same is rejected.
- Accepts a number or a string, unmasked or split into the printed groups (2, 3, 5 and 2 digits) by any run of whitespace,
.,-or/between two groups. Whitespace around the value is ignored. Anything else, such as another separator, a letter or a different grouping, is rejected. - A number is read only when it is a safe non-negative integer. A negative, fractional, non-finite or unsafe number is invalid.
- No official source publishes the check digit rule. Only the 12 positions and the CNO keeping the CEI number (Manual de Orientação do eSocial S-1.3, item 9.1) are official. The IN RFB 2.061/2021 has no check digit, and the eSocial only checks that the number exists in the Receita Federal base. The rule comes from third-party reference implementations, cross-checked against the CNO open data and SERPRO's example
000000336854. - A number loses its leading zeros, so a value that starts with
0is only accepted as a string:"000000336854"is valid and336854is not.
| Parameter | Type | Required |
|---|---|---|
value | string | number | yes |
| returns | boolean |
Check if a CEI (Cadastro Específico do INSS) number is valid. The CEI identifies an employer with no CNPJ, such as a construction work or a rural producer.
- Layout: 12 digits printed as
00.000.00000/00, 11 base digits and one check digit. - A number loses its leading zeros, so a value that starts with
0is only accepted as a string:isValidCei('000000336854')istrueandisValidCei(336854)isfalse. - Only the 12 digits are official: no norm, layout or manual of the Receita Federal publishes the check digit, which follows the community references below and agrees with the CNO open dataset and with SERPRO's example
000000336854.
import { isValidCei } from '@brazilian-utils/brazilian-utils';
isValidCei('11.583.00249/85'); // true
isValidCei('277297118187'); // true
isValidCei(249859674386); // true
isValidCei(-249859674386); // false (not a non-negative safe integer)
isValidCei('24.985.96743/68'); // false (invalid check digit)
isValidCei('000000000000'); // false (repeated digits)Source: SERPRO, CNO cadastro (12 positions), eSocial MOS S-1.3, item 9.1 (the CNO keeps the CEI number); check digit per yii2-br-validator, Bigai.Documentos.Brasil and the CNO open dataset.
Code: brazilian-utils/javascriptTry it with JavaScript isValidCei
Shared test cases (27) and the result in each library cei.isValid
Format
- JavaScript library
- Python library
- Go library
- Ruby library7 cases fail
- Rust library
- .NET library1 case fails
- Erlang library
Formats a CEI with the usual mask 00.000.00000/00.
The reference implementations of the check digit agree on this mask (the Receita Federal does not print it).
- The mask is applied as far as the digits go, so a value being typed is masked progressively, and digits beyond the 12th are dropped.
options.padfirst left-pads with zeros to 12 digits. - A number is read only when it is a safe non-negative integer. A negative, fractional, non-finite or unsafe number gives an empty string (2.4.0 read the digits of any number, sign and decimal point dropped).
options.padon a value with no digits ("","---",null) still gives an empty string. Until 2.4.0""and"---"gave the whole zero mask.
| Parameter | Type | Required |
|---|---|---|
value | string | number | yes |
options | FormatCeiOptions | no |
options.pad | boolean | no |
| returns | string |
Format a CEI (Cadastro Específico do INSS) number with the usual 00.000.00000/00 mask.
- Options (
FormatCeiOptions):padleft-pads the value with zeros up to 12 digits (defaultfalse). An empty value, or one without digits, gives''even withpad.
import { formatCei } from '@brazilian-utils/brazilian-utils';
formatCei('277297118187'); // 27.729.71181/87
formatCei(249859674386); // 24.985.96743/86
formatCei('249', { pad: true }); // 00.000.00002/49Try it with JavaScript formatCei
Shared test cases (20) and the result in each library cei.format
Parse
- JavaScript library
- Python library
- Go library
- Ruby library2 cases fail
- Rust library
- .NET library
- Erlang library
Removes CEI formatting and keeps only digits, capped at 12 digits.
- A number is read only when it is a safe non-negative integer. A negative, fractional, non-finite or unsafe number gives an empty string (2.4.0 read the digits of any number, sign and decimal point dropped).
| Parameter | Type | Required |
|---|---|---|
value | string | number | yes |
| returns | string |
Remove CEI (Cadastro Específico do INSS) formatting, keep only digits, and cap the result to 12 digits.
import { parseCei } from '@brazilian-utils/brazilian-utils';
parseCei('27.729.71181/87'); // '277297118187'Try it with JavaScript parseCei
Shared test cases (9) and the result in each library cei.parse
Official sources
Last updated on
