CAEPF

Cadastro de Atividade Econômica da Pessoa Física, the registration of individuals who employ workers (replaced the CEI for them).

  • Parity matrix

Validate

Validates a CAEPF: 14 digits, the 9-digit CPF base of the holder, a 3-digit sequence and 2 check digits. The CAEPF replaced the CEI for individuals who hire employees, such as rural producers.

  • Both check digits follow the CNPJ modulus 11. Then the resulting pair is shifted by 12, wrapping around 100.
  • A value whose 12-digit base (the CPF base and the sequence) has all digits the same is rejected.
  • The value may be a number or a string of 14 digits. Between the printed groups (3, 3, 3, 3 and 2 digits) there may be any run of whitespace, ., - or /, and any of those runs may be left out, so 293118.610/00184 is valid. Whitespace around the value is ignored. Anything else, such as another separator, a letter or a separator inside a group, 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 14 positions and the 9-digit CPF base are official (SERPRO's documentation of the Receita Federal cadastro). The IN RFB 1.828/2018 has no check digit, and the eSocial only checks that the number exists in the Receita Federal base. The 3 + 2 split of the last 5 digits and the rule come from third-party reference implementations. They accept SERPRO's example 00000002500171.
  • A number loses its leading zeros, so a value that starts with 0 is only accepted as a string.
ParameterTypeRequired
valuestring | numberyes
returnsboolean

Check if a CAEPF (Cadastro de Atividade Econômica da Pessoa Física) number is valid. The CAEPF replaced the CEI for individuals who hire employees, such as rural producers.

  • Layout: 14 digits printed as 000.000.000/000-00: the 9-digit CPF base of the holder, a 3-digit sequence and 2 check digits.
  • Both check digits follow the CNPJ's modulus 11; the pair is then shifted by 12, wrapping around 100.
  • A number loses its leading zeros, so a value that starts with 0 is only accepted as a string: isValidCaepf('00000002500171') is true and isValidCaepf(2500171) is false.
  • Only the 14 positions and the CPF base are official (SERPRO: "9 primeiros números do CPF + número de inscrição resumido" of 5 positions). The split of those 5 into a sequence and 2 check digits, the check digit rule and the shift of 12 come from the community references below; they agree with SERPRO's example 00000002500171.
import { isValidCaepf } from '@brazilian-utils/brazilian-utils';

isValidCaepf('293.118.610/001-84'); // true
isValidCaepf('41142260000101'); // true
isValidCaepf(29311861000184); // true
isValidCaepf(-29311861000184); // false (not a non-negative safe integer)
isValidCaepf('29311861000185'); // false (invalid check digits)
isValidCaepf('00000000000000'); // false (repeated base digits)
isValidCaepf('00000000000012'); // false (repeated base digits)

Source: SERPRO, CAEPF cadastro (14 positions); check digits per ghiorzi.org and brazilian-values.

Code: brazilian-utils/javascript
Try it with JavaScript isValidCaepf
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 (29) and the result in each library caepf.isValid

Format

Formats a CAEPF with the mask 000.000.000/000-00.

  • The mask is applied as far as the digits go, so a value being typed is masked progressively, and digits beyond the 14th are dropped. options.pad first left-pads with zeros to 14 digits.
  • A number is read only when it is a safe non-negative integer. A negative, fractional, non-finite or unsafe number returns an empty string (2.4.0 read the digits of any number, sign and decimal point dropped).
  • An empty value, or one without digits, returns an empty string even with pad. Until 2.4.0 pad returned the whole zero mask (000.000.000/000-00).
ParameterTypeRequired
valuestring | numberyes
optionsFormatCaepfOptionsno
options.padbooleanno
returnsstring

Format a CAEPF (Cadastro de Atividade Econômica da Pessoa Física) number with the usual 000.000.000/000-00 mask.

  • Same rules as formatCei, with pad (FormatCaepfOptions) padding up to 14 digits (default false).
import { formatCaepf } from '@brazilian-utils/brazilian-utils';

formatCaepf('29311861000184'); // 293.118.610/001-84
formatCaepf(41142260000101); // 411.422.600/001-01
formatCaepf('184', { pad: true }); // 000.000.000/001-84
Code: brazilian-utils/javascript
Try it with JavaScript formatCaepf
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 caepf.format

Parse

Removes CAEPF formatting and keeps only digits, capped at 14 digits.

  • A number is read only when it is a safe non-negative integer. A negative, fractional, non-finite or unsafe number returns an empty string (2.4.0 read the digits of any number, sign and decimal point dropped).
ParameterTypeRequired
valuestring | numberyes
returnsstring

Remove CAEPF (Cadastro de Atividade Econômica da Pessoa Física) formatting, keep only digits, and cap the result to 14 digits.

import { parseCaepf } from '@brazilian-utils/brazilian-utils';

parseCaepf('293.118.610/001-84'); // '29311861000184'
Code: brazilian-utils/javascript
Try it with JavaScript parseCaepf
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 caepf.parse

Official sources

See also CEI, CNO

Last updated on

On this page