Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/is-valid-license-plate/is-valid-license-plate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ describe("isValidLicensePlate", () => {
it("when mercosul license plate format is valid", () => {
expect(isValidLicensePlate("abc1d23")).toBe(true);
expect(isValidLicensePlate("ABC1D23")).toBe(true);

expect(isValidLicensePlate("ABC12D3")).toBe(true);
expect(isValidLicensePlate("abc12d3")).toBe(true);
});
});
});
11 changes: 6 additions & 5 deletions src/is-valid-license-plate/is-valid-license-plate.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const mercosulRegex = /^[a-z]{3}[0-9]{1}[a-z]{1}[0-9]{2}$/i;
const mercosulRegex =
/^[a-z]{3}[0-9]{1}[a-z]{1}[0-9]{2}$|^[a-z]{3}[0-9]{2}[a-z]{1}[0-9]{1}$/i;

const brazilianLicensePlateRegex = /^[a-z]{3}-?[0-9]{4}$/i;

/**
* Validates if a Brazilian license plate (placa de carro) is valid.
* Supports both the old Brazilian format (ABC-1234) and the new Mercosul format (ABC1D23).
* Validates if a Brazilian license plate (placa de carro ou moto) is valid.
* Supports the old Brazilian format (ABC-1234) and the Mercosul format for cars (ABC1D23) and motorcycles (ABC12D3).
*
* @param {string} value - The license plate value to be validated.
* @returns {boolean} True if the license plate is valid, false otherwise.
Expand All @@ -13,8 +14,8 @@ const brazilianLicensePlateRegex = /^[a-z]{3}-?[0-9]{4}$/i;
* ```typescript
* isValidLicensePlate("abc1234"); // true (Brazilian format)
* isValidLicensePlate("ABC-1234"); // true (Brazilian format with hyphen)
* isValidLicensePlate("abc1d23"); // true (Mercosul format)
* isValidLicensePlate("ABC1D23"); // true (Mercosul format)
* isValidLicensePlate("abc1d23"); // true (Mercosul format - Car)
* isValidLicensePlate("ABC12D3"); // true (Mercosul format - Motorcycle)
* isValidLicensePlate("invalid"); // false
* ```
*/
Expand Down
Loading