Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(isLicensePlate): add support for Swedish license plates #1665

Merged
merged 6 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,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`.<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.
**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.
**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`).
**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', 'sv-SE']` 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.<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'.
Expand Down
2 changes: 2 additions & 0 deletions src/lib/isLicensePlate.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const validators = {
/^[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),
'sv-SE': str =>
/(^[ABCDEFGHJKLMNOPRSTUWXYZ]{3}[ ]?[\d]{2}[ABCDEFGHJKLMNOPRSTUWXYZ\d]$)|(^[A-ZÅÄÖ ]{2,7}$)/.test(str),
elmaxe marked this conversation as resolved.
Show resolved Hide resolved
};

export default function isLicensePlate(str, locale) {
Expand Down
37 changes: 37 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -10722,6 +10722,43 @@ describe('Validators', () => {
'FS AB 1234 A',
],
});
test({
validator: 'isLicensePlate',
args: ['sv-SE'],
valid: [
'ABC 123',
'ABC 12A',
'ABC123',
'ABC12A',
'A WORD',
'WORD',
'ÅSNA',
'EN VARG',
'CERISE',
'AA',
'ABCDEFG',
'ÅÄÖ',
'ÅÄÖ ÅÄÖ',
],
invalid: [
'',
'IQV 123',
'IQV123',
'ABI 12Q',
'ÅÄÖ 123',
'ÅÄÖ 12A',
'AB1 A23',
'AB1 12A',
'lower',
'abc 123',
'abc 12A',
'abc 12a',
'AbC 12a',
'WORDLONGERTHANSEVENCHARACTERS',
'A',
'ABC-123',
],
});
});
it('should validate english VAT numbers', () => {
test({
Expand Down