CEI

Cadastro Específico do INSS, the registration of employers without a CNPJ (construction works, rural producers), superseded by the CNO and the CAEPF.

  • Parity matrix

Validate

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 0 is only accepted as a string: "000000336854" is valid and 336854 is not.
ParameterTypeRequired
valuestring | numberyes
returnsboolean

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 0 is only accepted as a string: isValidCei('000000336854') is true and isValidCei(336854) is false.
  • 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/javascript
Try it with JavaScript isValidCei
The inputs start with the first shared case. Change one to see the new result.

Runs @brazilian-utils/brazilian-utils 2.5.0 in your browser.

Shared test cases (27) and the result in each library cei.isValid

Format

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.pad first 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.pad on a value with no digits ("", "---", null) still gives an empty string. Until 2.4.0 "" and "---" gave the whole zero mask.
ParameterTypeRequired
valuestring | numberyes
optionsFormatCeiOptionsno
options.padbooleanno
returnsstring

Format a CEI (Cadastro Específico do INSS) number with the usual 00.000.00000/00 mask.

  • Options (FormatCeiOptions): pad left-pads the value with zeros up to 12 digits (default false). An empty value, or one without digits, gives '' even with pad.
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/49
Code: brazilian-utils/javascript
Try it with JavaScript formatCei
The inputs start with the first shared case. Change one to see the new result.

Runs @brazilian-utils/brazilian-utils 2.5.0 in your browser.

Shared test cases (20) and the result in each library cei.format

Parse

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).
ParameterTypeRequired
valuestring | numberyes
returnsstring

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'
Code: brazilian-utils/javascript
Try it with JavaScript parseCei
The inputs start with the first shared case. Change one to see the new result.

Runs @brazilian-utils/brazilian-utils 2.5.0 in your browser.

Shared test cases (9) and the result in each library cei.parse

Official sources

See also CNO, CAEPF

Last updated on

On this page