diff --git a/README.md b/README.md index b2896b73f..e72257f1f 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,7 @@ Validator | Description **isJWT(str)** | check if the string is valid JWT token. **isLatLong(str [, options])** | check if the string is a valid latitude-longitude coordinate in the format `lat,long` or `lat, long`.

`options` is an object that defaults to `{ checkDMS: false }`. Pass `checkDMS` as `true` to validate DMS(degrees, minutes, and seconds) latitude-longitude format. **isLength(str [, options])** | check if the string's length falls in a range.

`options` is an object which defaults to `{min:0, max: undefined}`. Note: this function takes into account surrogate pairs. -**isLicensePlate(str [, locale])** | check if string matches the format of a country's license plate.

(locale is one of `['de-DE', 'de-LI', 'pt-PT', 'sq-AL']` or `any`) +**isLicensePlate(str [, locale])** | check if string matches the format of a country's license plate.

(locale is one of `['de-DE', 'de-LI', 'pt-PT', 'sq-AL', 'pt-BR'']` or `any`). **isLocale(str)** | check if the string is a locale **isLowercase(str)** | check if the string is lowercase. **isMACAddress(str)** | check if the string is a MAC address.

`options` is an object which defaults to `{no_colons: false}`. If `no_colons` is true, the validator will allow MAC addresses without the colons. 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'. diff --git a/src/lib/isLicensePlate.js b/src/lib/isLicensePlate.js index c4b010d48..c0e23bd06 100644 --- a/src/lib/isLicensePlate.js +++ b/src/lib/isLicensePlate.js @@ -8,6 +8,8 @@ const validators = { /^([A-Z]{2}|[0-9]{2})[ -·]?([A-Z]{2}|[0-9]{2})[ -·]?([A-Z]{2}|[0-9]{2})$/.test(str), 'sq-AL': str => /^[A-Z]{2}[- ]?((\d{3}[- ]?(([A-Z]{2})|T))|(R[- ]?\d{3}))$/.test(str), + 'pt-BR': str => + /^[A-Z]{3}[ -]?[0-9][A-Z][0-9]{2}|[A-Z]{3}[ -]?[0-9]{4}$/.test(str), }; export default function isLicensePlate(str, locale) { diff --git a/test/validators.js b/test/validators.js index b9899b626..de36b80cc 100644 --- a/test/validators.js +++ b/test/validators.js @@ -10292,6 +10292,28 @@ describe('Validators', () => { 'AAA 00 AAA', ], }); + test({ + validator: 'isLicensePlate', + args: ['pt-BR'], + valid: [ + 'ABC1234', + 'ABC 1234', + 'ABC-1234', + 'ABC1D23', + 'ABC1K23', + 'ABC1Z23', + 'ABC 1D23', + 'ABC-1D23', + ], + invalid: [ + '', + 'AA 0 A', + 'AAA 00 AAA', + 'ABCD123', + 'AB12345', + 'AB123DC', + ], + }); test({ validator: 'isLicensePlate', args: ['any'],