From f5df7b86dc4c1c849f015ebc406dfbed4f7e43d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Tyrkk=C3=B6?= Date: Sat, 30 Oct 2021 12:39:32 +0300 Subject: [PATCH] feat: added finnish locale to isAlpha and isAlphanumeric (#1837) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Markus Tyrkkö --- README.md | 4 ++-- src/lib/alpha.js | 2 ++ test/validators.js | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9b6083b29..4dac913cf 100644 --- a/README.md +++ b/README.md @@ -85,8 +85,8 @@ Validator | Description **contains(str, seed [, options ])** | check if the string contains the seed.

`options` is an object that defaults to `{ ignoreCase: false}`.
`ignoreCase` specified whether the case of the substring be same or not. **equals(str, comparison)** | check if the string matches the comparison. **isAfter(str [, date])** | check if the string is a date that's after the specified date (defaults to now). -**isAlpha(str [, locale, options])** | check if the string contains only letters (a-zA-Z).

Locale is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fa-IR', 'fr-CA', 'fr-FR', 'he', 'hi-IN', 'hu-HU', 'it-IT', 'ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sk-SK', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`) and defaults to `en-US`. Locale list is `validator.isAlphaLocales`. options is an optional object that can be supplied with the following key(s): ignore which can either be a String or RegExp of characters to be ignored e.g. " -" will ignore spaces and -'s. -**isAlphanumeric(str [, locale, options])** | check if the string contains only letters and numbers (a-zA-Z0-9).

Locale is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fa-IR', 'fr-CA', 'fr-FR', 'he', 'hi-IN', 'hu-HU', 'it-IT', 'ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sk-SK', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`) and defaults to `en-US`. Locale list is `validator.isAlphanumericLocales`. options is an optional object that can be supplied with the following key(s): ignore which can either be a String or RegExp of characters to be ignored e.g. " -" will ignore spaces and -'s. +**isAlpha(str [, locale, options])** | check if the string contains only letters (a-zA-Z).

Locale is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fa-IR', 'fi-FI', 'fr-CA', 'fr-FR', 'he', 'hi-IN', 'hu-HU', 'it-IT', 'ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sk-SK', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`) and defaults to `en-US`. Locale list is `validator.isAlphaLocales`. options is an optional object that can be supplied with the following key(s): ignore which can either be a String or RegExp of characters to be ignored e.g. " -" will ignore spaces and -'s. +**isAlphanumeric(str [, locale, options])** | check if the string contains only letters and numbers (a-zA-Z0-9).

Locale is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fa-IR', 'fi-FI', 'fr-CA', 'fr-FR', 'he', 'hi-IN', 'hu-HU', 'it-IT', 'ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sk-SK', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`) and defaults to `en-US`. Locale list is `validator.isAlphanumericLocales`. options is an optional object that can be supplied with the following key(s): ignore which can either be a String or RegExp of characters to be ignored e.g. " -" will ignore spaces and -'s. **isAscii(str)** | check if the string contains ASCII chars only. **isBase32(str)** | check if a string is base32 encoded. **isBase58(str)** | check if a string is base58 encoded. diff --git a/src/lib/alpha.js b/src/lib/alpha.js index 27d3fbc6c..d663eded0 100644 --- a/src/lib/alpha.js +++ b/src/lib/alpha.js @@ -8,6 +8,7 @@ export const alpha = { 'el-GR': /^[Α-ώ]+$/i, 'es-ES': /^[A-ZÁÉÍÑÓÚÜ]+$/i, 'fa-IR': /^[ابپتثجچحخدذرزژسشصضطظعغفقکگلمنوهی]+$/i, + 'fi-FI': /^[A-ZÅÄÖ]+$/i, 'fr-FR': /^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i, 'it-IT': /^[A-ZÀÉÈÌÎÓÒÙ]+$/i, 'nb-NO': /^[A-ZÆØÅ]+$/i, @@ -42,6 +43,7 @@ export const alphanumeric = { 'de-DE': /^[0-9A-ZÄÖÜß]+$/i, 'el-GR': /^[0-9Α-ω]+$/i, 'es-ES': /^[0-9A-ZÁÉÍÑÓÚÜ]+$/i, + 'fi-FI': /^[0-9A-ZÅÄÖ]+$/i, 'fr-FR': /^[0-9A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i, 'it-IT': /^[0-9A-ZÀÉÈÌÎÓÒÙ]+$/i, 'hu-HU': /^[0-9A-ZÁÉÍÓÖŐÚÜŰ]+$/i, diff --git a/test/validators.js b/test/validators.js index aa08f07c1..8d2315542 100644 --- a/test/validators.js +++ b/test/validators.js @@ -1497,6 +1497,24 @@ describe('Validators', () => { }); }); + it('should validate finnish alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['fi-FI'], + valid: [ + 'äiti', + 'Öljy', + 'Åke', + 'testÖ', + ], + invalid: [ + 'AİıÖöÇ窺ĞğÜüZ', + 'äöå123', + '', + ], + }); + }); + it('should validate kurdish alpha strings', () => { test({ validator: 'isAlpha', @@ -1981,6 +1999,24 @@ describe('Validators', () => { }); }); + it('should validate finnish alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['fi-FI'], + valid: [ + 'äiti124', + 'ÖLJY1234', + '123Åke', + '451åå23', + ], + invalid: [ + 'AİıÖöÇ窺ĞğÜüZ', + 'foo!!', + '', + ], + }); + }); + it('should validate german alphanumeric strings', () => { test({ validator: 'isAlphanumeric',