From b91227e36f55927e34c14f720bc0697dd4a89fdf Mon Sep 17 00:00:00 2001 From: "Brian T. Whaley" Date: Sat, 6 Aug 2022 01:15:32 -0400 Subject: [PATCH 1/5] Add Belarusian [be-BY] and Romanian [ro-RO] to isAlpha and IsAlphanumeric --- README.md | 4 +-- src/lib/alpha.js | 4 +++ test/validators.js | 86 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 274acff48..a4f426aec 100644 --- a/README.md +++ b/README.md @@ -92,8 +92,8 @@ Validator | Description **contains(str, seed [, options ])** | check if the string contains the seed.

`options` is an object that defaults to `{ ignoreCase: false, minOccurrences: 1 }`.
Options:
`ignoreCase`: Ignore case when doing comparison, default false
`minOccurences`: Minimum number of occurrences for the seed in the string. Defaults to 1. **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', 'bn', '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', 'si-LK', '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', 'bn', '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', 'si-LK', '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', 'be-BY', 'bg-BG', 'bn', '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', 'ro-RO', 'ru-RU', 'si-LK', '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', 'bn', 'be-BY', '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', 'ro-RO', 'ru-RU', 'si-LK', '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 [, options])** | check if a string is base32 encoded. `options` is optional and defaults to `{crockford: false}`.
When `crockford` is true it tests the given base32 encoded string using [Crockford's base32 alternative](http://www.crockford.com/base32.html). **isBase58(str)** | check if a string is base58 encoded. diff --git a/src/lib/alpha.js b/src/lib/alpha.js index c941c9bd7..416051440 100644 --- a/src/lib/alpha.js +++ b/src/lib/alpha.js @@ -1,6 +1,7 @@ export const alpha = { 'en-US': /^[A-Z]+$/i, 'az-AZ': /^[A-VXYZÇƏĞİıÖŞÜ]+$/i, + 'be-BY': /^[ёа-зй-шы-яЁА-ЗЙ-ШЫІіЎў]+$/i, /* BELARUSIAN */ 'bg-BG': /^[А-Я]+$/i, 'cs-CZ': /^[A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i, 'da-DK': /^[A-ZÆØÅ]+$/i, @@ -17,6 +18,7 @@ export const alpha = { 'hu-HU': /^[A-ZÁÉÍÓÖŐÚÜŰ]+$/i, 'pl-PL': /^[A-ZĄĆĘŚŁŃÓŻŹ]+$/i, 'pt-PT': /^[A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i, + 'ro-RO': /^[A-ZĂÂÎȘȚăâîșț]+$/i, /* ROMANIAN */ 'ru-RU': /^[А-ЯЁ]+$/i, 'sl-SI': /^[A-ZČĆĐŠŽ]+$/i, 'sk-SK': /^[A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i, @@ -39,6 +41,7 @@ export const alpha = { export const alphanumeric = { 'en-US': /^[0-9A-Z]+$/i, 'az-AZ': /^[0-9A-VXYZÇƏĞİıÖŞÜ]+$/i, + 'be-BY': /^[0-9ёа-зй-шы-яЁА-ЗЙ-ШЫІіЎў]+$/i, /* BELARUSIAN */ 'bg-BG': /^[0-9А-Я]+$/i, 'cs-CZ': /^[0-9A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i, 'da-DK': /^[0-9A-ZÆØÅ]+$/i, @@ -54,6 +57,7 @@ export const alphanumeric = { 'nn-NO': /^[0-9A-ZÆØÅ]+$/i, 'pl-PL': /^[0-9A-ZĄĆĘŚŁŃÓŻŹ]+$/i, 'pt-PT': /^[0-9A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i, + 'ro-RO': /^[0-9A-ZĂÂÎȘȚăâîșț]+$/i, /* ROMANIAN */ 'ru-RU': /^[0-9А-ЯЁ]+$/i, 'sl-SI': /^[0-9A-ZČĆĐŠŽ]+$/i, 'sk-SK': /^[0-9A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i, diff --git a/test/validators.js b/test/validators.js index a02006be9..653037423 100644 --- a/test/validators.js +++ b/test/validators.js @@ -1403,6 +1403,28 @@ describe('Validators', () => { }); }); + it('should validate belarusian alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['be-BY'], + valid: [ + 'Прывітанне', + 'Дзякуй', + 'Дзякуй', + 'Выдатна', + 'Прабачце', + ], + invalid: [ + 'abc1', + ' foo ', + 'Прывітанне123', + '123Дзякуй', + '', + ' ', + ], + }); + }); + it('should validate bulgarian alpha strings', () => { test({ validator: 'isAlpha', @@ -1748,6 +1770,27 @@ describe('Validators', () => { }); }); + it('should validate romanian alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['ro-RO'], + valid: [ + 'Călătoresc', + 'astăzi', + 'frumoasă', + 'Bună', + 'Sâmbătă', + 'Duminică', + 'mână', + ], + invalid: [ + '12řiď ', + 'blé!!', + 'föö!2!', + ], + }); + }); + it('should validate serbian cyrillic alpha strings', () => { test({ validator: 'isAlpha', @@ -2095,6 +2138,28 @@ describe('Validators', () => { }); }); + it('should validate belarusian alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['be-BY'], + valid: [ + '123Прывітанне', + 'Дзякуй123', + '1Дзякуй', + 'Выдатна1', + '123Прабачце', + ], + invalid: [ + 'abc1', + ' foo ', + '', + ' ', + '789 ', + 'hello000', + ], + }); + }); + it('should validate bulgarian alphanumeric strings', () => { test({ validator: 'isAlphanumeric', @@ -2304,6 +2369,27 @@ describe('Validators', () => { }); }); + it('should validate romanian alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['ro-RO'], + valid: [ + '1Călătoresc', + 'astăzi2', + '3frumoasă', + 'Bună123', + '123Sâmbătă', + 'Duminică', + 'mână', + ], + invalid: [ + ' ', + 'foo!!', + '123!', + ], + }); + }); + it('should validate spanish alphanumeric strings', () => { test({ validator: 'isAlphanumeric', From 40298cf6bf14f12884c3a398409fe2dc07651d85 Mon Sep 17 00:00:00 2001 From: Brian Whaley Date: Wed, 10 Aug 2022 13:18:54 -0400 Subject: [PATCH 2/5] Update src/lib/alpha.js Co-authored-by: Rik Smale <13023439+WikiRik@users.noreply.github.com> --- src/lib/alpha.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/alpha.js b/src/lib/alpha.js index 416051440..98ceaabf2 100644 --- a/src/lib/alpha.js +++ b/src/lib/alpha.js @@ -1,7 +1,7 @@ export const alpha = { 'en-US': /^[A-Z]+$/i, 'az-AZ': /^[A-VXYZÇƏĞİıÖŞÜ]+$/i, - 'be-BY': /^[ёа-зй-шы-яЁА-ЗЙ-ШЫІіЎў]+$/i, /* BELARUSIAN */ + 'be-BY': /^[ёа-зй-шы-яЁА-ЗЙ-ШЫІіЎў]+$/i, 'bg-BG': /^[А-Я]+$/i, 'cs-CZ': /^[A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i, 'da-DK': /^[A-ZÆØÅ]+$/i, From d6109a1cf88c026ed764d021b96c0316821c0b29 Mon Sep 17 00:00:00 2001 From: Brian Whaley Date: Wed, 10 Aug 2022 13:18:59 -0400 Subject: [PATCH 3/5] Update src/lib/alpha.js Co-authored-by: Rik Smale <13023439+WikiRik@users.noreply.github.com> --- src/lib/alpha.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/alpha.js b/src/lib/alpha.js index 98ceaabf2..5251142cb 100644 --- a/src/lib/alpha.js +++ b/src/lib/alpha.js @@ -18,7 +18,7 @@ export const alpha = { 'hu-HU': /^[A-ZÁÉÍÓÖŐÚÜŰ]+$/i, 'pl-PL': /^[A-ZĄĆĘŚŁŃÓŻŹ]+$/i, 'pt-PT': /^[A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i, - 'ro-RO': /^[A-ZĂÂÎȘȚăâîșț]+$/i, /* ROMANIAN */ + 'ro-RO': /^[A-ZĂÂÎȘȚăâîșț]+$/i, 'ru-RU': /^[А-ЯЁ]+$/i, 'sl-SI': /^[A-ZČĆĐŠŽ]+$/i, 'sk-SK': /^[A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i, From 70837de32106bf7ff89998ae269e15a00156837d Mon Sep 17 00:00:00 2001 From: Brian Whaley Date: Wed, 10 Aug 2022 13:19:04 -0400 Subject: [PATCH 4/5] Update src/lib/alpha.js Co-authored-by: Rik Smale <13023439+WikiRik@users.noreply.github.com> --- src/lib/alpha.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/alpha.js b/src/lib/alpha.js index 5251142cb..8d6a0ad80 100644 --- a/src/lib/alpha.js +++ b/src/lib/alpha.js @@ -41,7 +41,7 @@ export const alpha = { export const alphanumeric = { 'en-US': /^[0-9A-Z]+$/i, 'az-AZ': /^[0-9A-VXYZÇƏĞİıÖŞÜ]+$/i, - 'be-BY': /^[0-9ёа-зй-шы-яЁА-ЗЙ-ШЫІіЎў]+$/i, /* BELARUSIAN */ + 'be-BY': /^[0-9ёа-зй-шы-яЁА-ЗЙ-ШЫІіЎў]+$/i, 'bg-BG': /^[0-9А-Я]+$/i, 'cs-CZ': /^[0-9A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i, 'da-DK': /^[0-9A-ZÆØÅ]+$/i, From 496ae30c84f8351d8ef49e115f62ed177dfb5217 Mon Sep 17 00:00:00 2001 From: Brian Whaley Date: Wed, 10 Aug 2022 13:19:09 -0400 Subject: [PATCH 5/5] Update src/lib/alpha.js Co-authored-by: Rik Smale <13023439+WikiRik@users.noreply.github.com> --- src/lib/alpha.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/alpha.js b/src/lib/alpha.js index 8d6a0ad80..134aeb27e 100644 --- a/src/lib/alpha.js +++ b/src/lib/alpha.js @@ -57,7 +57,7 @@ export const alphanumeric = { 'nn-NO': /^[0-9A-ZÆØÅ]+$/i, 'pl-PL': /^[0-9A-ZĄĆĘŚŁŃÓŻŹ]+$/i, 'pt-PT': /^[0-9A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i, - 'ro-RO': /^[0-9A-ZĂÂÎȘȚăâîșț]+$/i, /* ROMANIAN */ + 'ro-RO': /^[0-9A-ZĂÂÎȘȚăâîșț]+$/i, 'ru-RU': /^[0-9А-ЯЁ]+$/i, 'sl-SI': /^[0-9A-ZČĆĐŠŽ]+$/i, 'sk-SK': /^[0-9A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i,