Passport

Brazilian passport numbers (2 letters and 6 digits).

  • Parity matrix

Validate

Validates a Brazilian passport number: 2 letters followed by 6 digits, after removing non-alphanumeric characters.

  • There is no check digit, so a well-formed number is not necessarily a real passport.
  • A numeric value is never valid, since it cannot start with the two letters.
  • The layout's only official source is the Polícia Federal FAQ ("duas letras ... e por seis dígitos subsequentes", example CS265436). Neither Decreto 5.978/2006 nor IN 173-DG/PF/2020 defines the number, and the FAQ forbids no letter, so none is rejected.

Pending decision

The reference (JS) is case-insensitive and ignores symbols (ab123456, AB-123.456 are valid). Erlang and Python accept only the strict uppercase form. See the open decision in docs/findings.md.

ParameterTypeRequired
passportstring | numberyes
returnsboolean

Check if a Brazilian passport number is valid: 2 letters followed by 6 digits.

  • There is no check digit, so a well-formed number is not necessarily a real passport.
  • The 2 letters (the "série") and 6 digits come from the Polícia Federal's FAQ; no norm defines the number (neither the Decreto nº 5.978/2006 nor the IN nº 173-DG/PF/2020, as amended up to the IN nº 283/2024), and the FAQ lists no forbidden letter.
import { isValidPassport } from '@brazilian-utils/brazilian-utils';

isValidPassport('AB123456'); // true
isValidPassport('ab123456'); // true (case-insensitive)
isValidPassport('AB-123.456'); // true (symbols are ignored)
isValidPassport('12345678'); // false

Source: Polícia Federal FAQ.

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

Format

Formats a passport number: upper-cased, without symbols, capped at 8 characters (the same operation as passport.parse).

  • It is an alias of passport.parse: it does not check the number, so a partial value (AB12) is formatted as it is.
  • A value that is not a string (for example a number) returns an empty string: a number is never a passport number, since the series is two letters.

Pending decision

The reference (JS) upper-cases lowercase and masked input. Erlang and Python accept only the strict uppercase form. See the open decision in docs/findings.md.

ParameterTypeRequired
passportstringyes
returnsstring

Format a Brazilian passport number: uppercase, without symbols, capped to 8 characters. It is the same operation as parsePassport, of which it is an alias.

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

formatPassport('ab123456'); // 'AB123456'
formatPassport('AB-123.456'); // 'AB123456'
Code: brazilian-utils/javascript
Try it with JavaScript formatPassport
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 passport.format

Parse

Removes every non-alphanumeric character from a passport number, upper-cases it and caps it at 8 characters.

  • A value that is not a string (for example a number) returns an empty string.
ParameterTypeRequired
passportstringyes
returnsstring

Remove all non-alphanumeric characters from a passport number, uppercase the result, and cap it to 8 characters.

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

parsePassport('AB-123.456'); // 'AB123456'
parsePassport(' AB 123 456 '); // 'AB123456'
Code: brazilian-utils/javascript
Try it with JavaScript parsePassport
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 (8) and the result in each library passport.parse

Generate

Generates a random valid passport number: 2 uppercase letters followed by 6 digits.

ParameterTypeRequired
returnsstring

Generate a random valid Brazilian passport number.

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

generatePassport(); // 'RY393097'
Code: brazilian-utils/javascript
Try it with JavaScript generatePassport
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 (1) and the result in each library passport.generate

Official sources

Last updated on

On this page