Passport
Brazilian passport numbers (2 letters and 6 digits).
Validate
- JavaScript library
- Python library4 cases fail
- Go library
- Ruby library
- Rust library1 case fails
- .NET library
- Erlang library4 cases fail
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.
| Parameter | Type | Required |
|---|---|---|
passport | string | number | yes |
| returns | boolean |
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'); // falseSource: Polícia Federal FAQ.
Code: brazilian-utils/javascriptTry it with JavaScript isValidPassport
Shared test cases (12) and the result in each library passport.isValid
Format
- JavaScript library
- Python library17 cases fail
- Go library
- Ruby library
- Rust library
- .NET library
- Erlang library17 cases fail
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.
| Parameter | Type | Required |
|---|---|---|
passport | string | yes |
| returns | string |
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'Try it with JavaScript formatPassport
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.
| Parameter | Type | Required |
|---|---|---|
passport | string | yes |
| returns | string |
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'Try it with JavaScript parsePassport
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.
| Parameter | Type | Required |
|---|---|---|
| returns | string |
Generate a random valid Brazilian passport number.
import { generatePassport } from '@brazilian-utils/brazilian-utils';
generatePassport(); // 'RY393097'Try it with JavaScript generatePassport
Shared test cases (1) and the result in each library passport.generate
Official sources
Last updated on
