CAEPF
Cadastro de Atividade Econômica da Pessoa Física, the registration of individuals who employ workers (replaced the CEI for them).
Validate
- JavaScript library
- Python library
- Go library3 cases fail
- Ruby library1 case fails
- Rust library
- .NET library3 cases fail
- Erlang library
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, so293118.610/00184is 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
0is only accepted as a string.
| Parameter | Type | Required |
|---|---|---|
value | string | number | yes |
| returns | boolean |
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
0is only accepted as a string:isValidCaepf('00000002500171')istrueandisValidCaepf(2500171)isfalse. - 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/javascriptTry it with JavaScript isValidCaepf
Shared test cases (29) and the result in each library caepf.isValid
Format
- JavaScript library
- Python library
- Go library
- Ruby library7 cases fail
- Rust library
- .NET library1 case fails
- Erlang library
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.padfirst 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.0padreturned the whole zero mask (000.000.000/000-00).
| Parameter | Type | Required |
|---|---|---|
value | string | number | yes |
options | FormatCaepfOptions | no |
options.pad | boolean | no |
| returns | string |
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, withpad(FormatCaepfOptions) padding up to 14 digits (defaultfalse).
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-84Try it with JavaScript formatCaepf
Shared test cases (20) and the result in each library caepf.format
Parse
- JavaScript library
- Python library
- Go library
- Ruby library2 cases fail
- Rust library
- .NET library
- Erlang library
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).
| Parameter | Type | Required |
|---|---|---|
value | string | number | yes |
| returns | string |
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'Try it with JavaScript parseCaepf
Shared test cases (9) and the result in each library caepf.parse
Official sources
Last updated on
