diff --git a/README.md b/README.md index 0f3393a25..c85590dd0 100644 --- a/README.md +++ b/README.md @@ -84,8 +84,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])** | 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', 'fr-FR', 'fa', 'fa-AF', 'fa-IR', 'he', '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', 'vi-VN']`) and defaults to `en-US`. Locale list is `validator.isAlphaLocales`. -**isAlphanumeric(str [, locale])** | check if the string contains only letters and numbers.

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', 'fr-FR', 'fa', 'fa-AF', 'fa-IR', 'he', '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', 'vi-VN']`) and defaults to `en-US`. Locale list is `validator.isAlphanumericLocales`. +**isAlpha(str [, locale])** | 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', 'az-AZ', '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', 'fr-FR', 'fa', 'fa-AF', 'fa-IR', 'he', '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', 'vi-VN']`) and defaults to `en-US`. Locale list is `validator.isAlphaLocales`. +**isAlphanumeric(str [, locale])** | check if the string contains only letters and numbers.

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', 'az-AZ', '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', 'fr-FR', 'fa', 'fa-AF', 'fa-IR', 'he', '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', 'vi-VN']`) and defaults to `en-US`. Locale list is `validator.isAlphanumericLocales`. **isAscii(str)** | check if the string contains ASCII chars only. **isBase32(str)** | check if a string is base32 encoded. **isBase64(str [, options])** | check if a string is base64 encoded. options is optional and defaults to `{urlSafe: false}`
when `urlSafe` is true it tests the given base64 encoded string is [url safe](https://base64.guru/standards/base64url) diff --git a/src/lib/alpha.js b/src/lib/alpha.js index 89c492213..acf69a8ac 100644 --- a/src/lib/alpha.js +++ b/src/lib/alpha.js @@ -1,5 +1,6 @@ export const alpha = { 'en-US': /^[A-Z]+$/i, + 'az-AZ': /^[A-VXYZÇƏĞİıÖŞÜ]+$/i, 'bg-BG': /^[А-Я]+$/i, 'cs-CZ': /^[A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i, 'da-DK': /^[A-ZÆØÅ]+$/i, @@ -31,6 +32,7 @@ export const alpha = { export const alphanumeric = { 'en-US': /^[0-9A-Z]+$/i, + 'az-AZ': /^[0-9A-VXYZÇƏĞİıÖŞÜ]+$/i, 'bg-BG': /^[0-9А-Я]+$/i, 'cs-CZ': /^[0-9A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i, 'da-DK': /^[0-9A-ZÆØÅ]+$/i, diff --git a/test/validators.js b/test/validators.js index dcae75229..55c1fa211 100644 --- a/test/validators.js +++ b/test/validators.js @@ -925,6 +925,29 @@ describe('Validators', () => { }); }); + it('should validate Azerbaijani alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['az-AZ'], + valid: [ + 'Azərbaycan', + 'Bakı', + 'üöğıəçş', + 'sizAzərbaycanlaşdırılmışlardansınızmı', + 'dahaBirDüzgünString', + 'abcçdeəfgğhxıijkqlmnoöprsştuüvyz', + ], + invalid: [ + 'rəqəm1', + ' foo ', + '', + 'ab(cd)', + 'simvol@', + 'wəkil', + ], + }); + }); + it('should validate bulgarian alpha strings', () => { test({ validator: 'isAlpha', @@ -1447,6 +1470,27 @@ describe('Validators', () => { }); }); + it('should validate Azerbaijani alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['az-AZ'], + valid: [ + 'Azərbaycan', + 'Bakı', + 'abc1', + 'abcç2', + '3kərə4kərə', + ], + invalid: [ + ' foo1 ', + '', + 'ab(cd)', + 'simvol@', + 'wəkil', + ], + }); + }); + it('should validate bulgarian alphanumeric strings', () => { test({ validator: 'isAlphanumeric',