From b4672f4670cb75aa16e5b8d0b1ac8476a286c54e Mon Sep 17 00:00:00 2001 From: Tomer Cohen Date: Sat, 5 Oct 2019 16:15:46 +0300 Subject: [PATCH 1/3] fix: typo in README (#1126) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 392095c08..39e27f3e5 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ Validator | Description **isBase32(str)** | check if a string is base32 encoded. **isBase64(str)** | check if a string is base64 encoded. **isBefore(str [, date])** | check if the string is a date that's before the specified date. -**isBIC(str)** | check if a string is a BIC (Bank Idenfication Code) or SWIFT code. +**isBIC(str)** | check if a string is a BIC (Bank Identification Code) or SWIFT code. **isBoolean(str)** | check if a string is a boolean. **isByteLength(str [, options])** | check if the string's length (in UTF-8 bytes) falls in a range.

`options` is an object which defaults to `{min:0, max: undefined}`. **isCreditCard(str)** | check if the string is a credit card. From 242c3bfbf6db5694e0018c71271a482916ae467c Mon Sep 17 00:00:00 2001 From: Tomer Cohen Date: Sat, 5 Oct 2019 16:18:57 +0300 Subject: [PATCH 2/3] feat: add hebrew support to isAlpha and isAlphanumeric (#1125) --- README.md | 4 ++-- src/lib/alpha.js | 2 ++ test/validators.js | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 39e27f3e5..826c3f8e7 100644 --- a/README.md +++ b/README.md @@ -77,8 +77,8 @@ Validator | Description ***contains(str, seed)*** | check if the string contains the seed. **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', '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`. -**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', '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`. +**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', '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']`) 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', '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']`) 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)** | check if a string is base64 encoded. diff --git a/src/lib/alpha.js b/src/lib/alpha.js index d20ea7855..edc7bbe31 100644 --- a/src/lib/alpha.js +++ b/src/lib/alpha.js @@ -24,6 +24,7 @@ export const alpha = { 'uk-UA': /^[А-ЩЬЮЯЄIЇҐі]+$/i, 'ku-IQ': /^[ئابپتجچحخدرڕزژسشعغفڤقکگلڵمنوۆھەیێيطؤثآإأكضصةظذ]+$/i, ar: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/, + he: /^[א-ת]+$/, }; export const alphanumeric = { @@ -52,6 +53,7 @@ export const alphanumeric = { 'uk-UA': /^[0-9А-ЩЬЮЯЄIЇҐі]+$/i, 'ku-IQ': /^[٠١٢٣٤٥٦٧٨٩0-9ئابپتجچحخدرڕزژسشعغفڤقکگلڵمنوۆھەیێيطؤثآإأكضصةظذ]+$/i, ar: /^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/, + he: /^[0-9א-ת]+$/, }; export const decimal = { diff --git a/test/validators.js b/test/validators.js index f2010c3a9..7c2b924a8 100644 --- a/test/validators.js +++ b/test/validators.js @@ -1242,6 +1242,23 @@ describe('Validators', () => { }); }); + it('should validate Hebrew alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['he'], + valid: [ + 'בדיקה', + 'שלום', + ], + invalid: [ + 'בדיקה123', + ' foo ', + 'abc1', + '', + ], + }); + }); + it('should error on invalid locale', () => { test({ validator: 'isAlpha', @@ -1646,6 +1663,23 @@ describe('Validators', () => { }); }); + it('should validate Hebrew alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['he'], + valid: [ + 'אבג123', + 'שלום11', + ], + invalid: [ + 'אבג ', + 'לא!!', + 'abc', + ' foo ', + ], + }); + }); + it('should error on invalid locale', () => { test({ validator: 'isAlphanumeric', From cff8a582ad9ca3b8361daa6074ff54f9d65dc0b4 Mon Sep 17 00:00:00 2001 From: Tony Date: Sat, 5 Oct 2019 15:21:08 +0200 Subject: [PATCH 3/3] fix: update build status travis on README (#1124) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 826c3f8e7..2d04496ff 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # validator.js [![NPM version][npm-image]][npm-url] -[![Build Status][travis-image]][travis-url] +[![Build Status](https://travis-ci.org/validatorjs/validator.js.svg?branch=master)](https://travis-ci.org/validatorjs/validator.js) [![Downloads][downloads-image]][npm-url] [![Backers on Open Collective](https://opencollective.com/validatorjs/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/validatorjs/sponsors/badge.svg)](#sponsors)