Skip to content

Commit 7989e5b

Browse files
feat(isLicensePlate): add support for pt-BR locale (#1588)
* License Plate validators: pt-BR and mercosur * Removing mercosur as it's not an actual valid country locale
1 parent 3c771e8 commit 7989e5b

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Validator | Description
131131
**isJWT(str)** | check if the string is valid JWT token.
132132
**isLatLong(str [, options])** | check if the string is a valid latitude-longitude coordinate in the format `lat,long` or `lat, long`.<br/><br/>`options` is an object that defaults to `{ checkDMS: false }`. Pass `checkDMS` as `true` to validate DMS(degrees, minutes, and seconds) latitude-longitude format.
133133
**isLength(str [, options])** | check if the string's length falls in a range.<br/><br/>`options` is an object which defaults to `{min:0, max: undefined}`. Note: this function takes into account surrogate pairs.
134-
**isLicensePlate(str [, locale])** | check if string matches the format of a country's license plate.<br/><br/>(locale is one of `['de-DE', 'de-LI', 'pt-PT', 'sq-AL']` or `any`)
134+
**isLicensePlate(str [, locale])** | check if string matches the format of a country's license plate.<br/><br/>(locale is one of `['de-DE', 'de-LI', 'pt-PT', 'sq-AL', 'pt-BR'']` or `any`).
135135
**isLocale(str)** | check if the string is a locale
136136
**isLowercase(str)** | check if the string is lowercase.
137137
**isMACAddress(str)** | check if the string is a MAC address.<br/><br/>`options` is an object which defaults to `{no_separators: false}`. If `no_separators` is true, the validator will allow MAC addresses without separators. Also, it allows the use of hyphens, spaces or dots e.g '01 02 03 04 05 ab', '01-02-03-04-05-ab' or '0102.0304.05ab'.

src/lib/isLicensePlate.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const validators = {
88
/^([A-Z]{2}|[0-9]{2})[ -·]?([A-Z]{2}|[0-9]{2})[ -·]?([A-Z]{2}|[0-9]{2})$/.test(str),
99
'sq-AL': str =>
1010
/^[A-Z]{2}[- ]?((\d{3}[- ]?(([A-Z]{2})|T))|(R[- ]?\d{3}))$/.test(str),
11+
'pt-BR': str =>
12+
/^[A-Z]{3}[ -]?[0-9][A-Z][0-9]{2}|[A-Z]{3}[ -]?[0-9]{4}$/.test(str),
1113
};
1214

1315
export default function isLicensePlate(str, locale) {

test/validators.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10403,6 +10403,28 @@ describe('Validators', () => {
1040310403
'AAA 00 AAA',
1040410404
],
1040510405
});
10406+
test({
10407+
validator: 'isLicensePlate',
10408+
args: ['pt-BR'],
10409+
valid: [
10410+
'ABC1234',
10411+
'ABC 1234',
10412+
'ABC-1234',
10413+
'ABC1D23',
10414+
'ABC1K23',
10415+
'ABC1Z23',
10416+
'ABC 1D23',
10417+
'ABC-1D23',
10418+
],
10419+
invalid: [
10420+
'',
10421+
'AA 0 A',
10422+
'AAA 00 AAA',
10423+
'ABCD123',
10424+
'AB12345',
10425+
'AB123DC',
10426+
],
10427+
});
1040610428
test({
1040710429
validator: 'isLicensePlate',
1040810430
args: ['any'],

0 commit comments

Comments
 (0)