Court case number

Court case numbers in the unified numbering of Resolução CNJ nº 65/2008 (NUP).

  • Parity matrix

Validate

Validates a court case number (Resolução CNJ nº 65/2008). It checks the NNNNNNN-DD.AAAA.J.TR.OOOO layout, the DD check digits (ISO 7064 MOD 97-10) and the J/TR pair.

  • J and TR must name a segment and a tribunal that exist (art. 1º, §§ 4º and 5º). J is 1 (STF), 2 (CNJ), 3 (STJ), 4 (Justiça Federal), 5 (Justiça do Trabalho), 6 (Justiça Eleitoral), 7 (Justiça Militar da União), 8 (Justiça Estadual) or 9 (Justiça Militar Estadual). TR is 00 for J 1, 2 and 3; for J 4, 01 to 06 (TRF) or 90 (CJF); for J 5, 00 (TST), 01 to 24 (TRT) or 90 (CSJT); for J 6, 00 (TSE) or 01 to 27 (TRE); for J 7, 00 (STM) or 01 to 12 (CJM); for J 8, 01 to 27 (TJ); for J 9, 13, 21 or 26 (TJM of MG, RS and SP).
  • The unidade de origem OOOO is only checked as four digits, because art. 1º, § 6º leaves its codification to each tribunal.
  • Accepts the 20 digits bare or with the CNJ mask, and only a string (a number is invalid). Whitespace, ., - and / (the mask characters cpf.isValid reads), in any run, are accepted between the NNNNNNN, DD, AAAA, J, TR and OOOO fields, or omitted, so 0002080-25.2012.515.0049 (J and TR fused) is valid. Whitespace around the value is ignored. A separator inside a field (000208-0252012.5.15.0049), at the start or the end of the value, any other character (_) and a letter make it invalid. Until 2.4.0 a slash between the fields made it invalid, so 0002080/25.2012.5.15.0049 was false.
  • The check digits follow art. 1º § 2º and Anexo VIII ("Cálculo do dígito verificador") of Resolução CNJ 65/2008. The TRF da 6ª Região (4.06) is valid per Resolução CNJ 477/2022.
  • The TRF6 example printed in Anexo II, 0000100-15.2008.406.0000, is fictitious, as the Anexo says. Written in the NNNNNNN-DD.AAAA.J.TR.OOOO form its check digits are 68, not 15, so the function accepts 0000100-68.2008.4.06.0000 and rejects the printed one.

Pending decision

Go, Python, Ruby and Rust reject numbers that the reference (JS) generates for the current year. The segment/tribunal rules need to be reconciled. See the open decision in docs/findings.md.

ParameterTypeRequired
valuestringyes
returnsboolean

Check if a processo jurídico number is valid, per Resolução CNJ nº 65/2008. Three things are checked: the NNNNNNN-DD.AAAA.J.TR.OOOO layout, the DD check digits (ISO 7064 MOD 97-10) and the J/TR pair.

  • J and TR must name an órgão and a tribunal that exist.
  • The unidade de origem (OOOO) is only checked as four digits.
import { isValidProcessoJuridico } from '@brazilian-utils/brazilian-utils';

isValidProcessoJuridico('00020802520125150049'); // true
isValidProcessoJuridico('0002080-25.2012.5.15.0049'); // true (CNJ mask)
isValidProcessoJuridico('0000100-68.2008.4.06.0000'); // true (TRF da 6ª Região)
isValidProcessoJuridico('0000100-23.2008.8.28.0000'); // false (no 28th Tribunal de Justiça)
isValidProcessoJuridico('ab00020802520125150049'); // false (letters are rejected)

Source: Resolução CNJ nº 65/2008, art. 1º (layout, J and TR) and Anexo VIII ("CÁLCULO DO DÍGITO VERIFICADOR"); the TRF da 6ª Região (4.06) per Resolução CNJ nº 477/2022.

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

Format

Formats a court case number with the CNJ mask NNNNNNN-DD.AAAA.J.TR.OOOO.

  • Every character that is not a digit is dropped first, and only the first 20 digits are kept. The mask is applied as far as the digits go, so a value being typed is masked progressively (00020802 gives 0002080-2).
  • options.pad first left-pads the value with zeros to 20 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.

Pending decision

The reference (JS) formats only the characters an incomplete value has. It returns an empty string for empty or invalid input. The other libraries return null. See the open decision in docs/findings.md.

ParameterTypeRequired
valuestring | numberyes
optionsFormatProcessoJuridicoOptionsno
options.padbooleanno
returnsstring

Format a processo jurídico number in the CNJ mask NNNNNNN-DD.AAAA.J.TR.OOOO.

  • Options (FormatProcessoJuridicoOptions): pad left-pads the value with zeros to 20 digits before masking (default false). An empty value, or one without digits, gives '' even with pad.
import { formatProcessoJuridico } from '@brazilian-utils/brazilian-utils';

formatProcessoJuridico('00020802520125150049'); // '0002080-25.2012.5.15.0049'
formatProcessoJuridico('20802520125150049', { pad: true }); // '0002080-25.2012.5.15.0049'

Source: Resolução CNJ nº 65/2008.

Code: brazilian-utils/javascript
Try it with JavaScript formatProcessoJuridico
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 (36) and the result in each library legalProcess.format

Parse

Removes court case number formatting and keeps only digits, capped at 20 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 processo jurídico formatting, keep only digits, and cap the result to 20 digits.

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

parseProcessoJuridico('0002080-25.2012.5.15.0049'); // '00020802520125150049'
Code: brazilian-utils/javascript
Try it with JavaScript parseProcessoJuridico
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 (19) and the result in each library legalProcess.parse

Generate

Generates a random valid court case number (20 digits, unformatted) in the NNNNNNNDDAAAAJTROOOO layout of Resolução CNJ nº 65/2008.

  • options.year sets the AAAA field: an integer from the current year to 9999 (default: the current year). options.court sets the segment J: an integer from 1 to 9 (default: random).
  • The function picks TR among the tribunals of the chosen segment, so the pair always names a court that exists. The sequence number and the unidade de origem are random and the check digits are computed.
  • Returns null when the year or the segment is out of range or not an integer, or when the options are not an object.
ParameterTypeRequired
paramsGenerateProcessoJuridicoParamsno
params.yearnumberno
params.courtnumberno
returnsstring | null

Generate a valid random processo jurídico number in the layout of Resolução CNJ nº 65/2008.

  • Options (GenerateProcessoJuridicoParams): year sets the AAAA field, an integer from the current year to 9999 (default: the current year); court sets the órgão J, from 1 to 9 (default: random).
  • TR is drawn among the tribunais of the chosen órgão, so the pair always names a court that exists.
  • Returns null when year or court is out of range.
import { generateProcessoJuridico } from '@brazilian-utils/brazilian-utils';

generateProcessoJuridico(); // '89478645020266070326'
generateProcessoJuridico({ year: 2026, court: 5 }); // '98412562120265087260' (Justiça do Trabalho, TRT da 8ª Região)
generateProcessoJuridico({ year: 10000 }); // null (year out of range)
generateProcessoJuridico({ court: 10 }); // null (no such órgão)

Source: Resolução CNJ nº 65/2008.

Code: brazilian-utils/javascript
Try it with JavaScript generateProcessoJuridico
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 legalProcess.generate

Decode

Reads the fields of a processo jurídico number: the sequential number, the check digits, the year, the segment of the Judiciary (órgão J), the tribunal and the unit of origin.

  • Returns null exactly when legalProcess.isValid returns false; the input rules are the same (the 20 digits, masked or not, as a string).
  • The result has sequentialNumber (NNNNNNN), checkDigits (DD), year (AAAA, a number), segment, segmentCode (J, '1' to '9'), tribunalCode (TR, two digits) and originUnit (OOOO). Codes are strings that keep their leading zeros.
  • segment names the órgão J: supreme-federal-court (1), national-council-of-justice (2), superior-court-of-justice (3), federal (4), labor (5), electoral (6), military (7), state (8) or state-military (9).
  • tribunalCode is 00 for the processes of the STF, the CNJ, the STJ, the TST, the TSE and the STM, 90 for the Conselho da Justiça Federal and the Conselho Superior da Justiça do Trabalho, and the number of the region or state otherwise. The result has no tribunal name.
  • The unit of origin is not checked: each tribunal codifies its own.
  • Each call returns a new object.
ParameterTypeRequired
valuestringyes
returnsProcessoJuridicoInfo | null

Read the fields of a processo jurídico number, as a ProcessoJuridicoInfo, or null when isValidProcessoJuridico would return false.

  • Fields: sequentialNumber (NNNNNNN), checkDigits (DD), year (AAAA, a number), segment (a name for the órgão J: 'supreme-federal-court', 'national-council-of-justice', 'superior-court-of-justice', 'federal', 'labor', 'electoral', 'military', 'state' or 'state-military'), segmentCode (J, '1' to '9'), tribunalCode (TR, two digits) and originUnit (OOOO). Codes are strings that keep their leading zeros.
  • tribunalCode is '00' for the processes of a superior court or of the STF, the CNJ, the STJ, the TST, the TSE and the STM, '90' for the Conselho da Justiça Federal and the Conselho Superior da Justiça do Trabalho, and the number of the region or state otherwise. The unit of origin is not checked: each tribunal codifies its own.
import { getProcessoJuridicoInfo } from '@brazilian-utils/brazilian-utils';

getProcessoJuridicoInfo('0002080-25.2012.5.15.0049');
// {
//   sequentialNumber: '0002080',
//   checkDigits: '25',
//   year: 2012,
//   segment: 'labor',
//   segmentCode: '5',
//   tribunalCode: '15',
//   originUnit: '0049',
// }

getProcessoJuridicoInfo('0000100-23.2008.8.28.0000'); // null (no 28th Tribunal de Justiça)

Source: Resolução CNJ nº 65/2008.

Code: brazilian-utils/javascript
Try it with JavaScript getProcessoJuridicoInfo
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 (34) and the result in each library legalProcess.getInfo

Official sources

Last updated on

On this page