Skip to content

Commit 7b47f53

Browse files
authored
feat(isAlpha, isAlphanumeric): add ko-KR locale (#1965)
1 parent d698f4f commit 7b47f53

3 files changed

Lines changed: 42 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ Validator | Description
9292
**contains(str, seed [, options ])** | check if the string contains the seed.<br/><br/>`options` is an object that defaults to `{ ignoreCase: false, minOccurrences: 1 }`.<br />Options: <br/> `ignoreCase`: Ignore case when doing comparison, default false<br/>`minOccurences`: Minimum number of occurrences for the seed in the string. Defaults to 1.
9393
**equals(str, comparison)** | check if the string matches the comparison.
9494
**isAfter(str [, date])** | check if the string is a date that's after the specified date (defaults to now).
95-
**isAlpha(str [, locale, options])** | check if the string contains only letters (a-zA-Z).<br/><br/>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', 'ja-JP', '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.
96-
**isAlphanumeric(str [, locale, options])** | check if the string contains only letters and numbers (a-zA-Z0-9).<br/><br/>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', 'ja-JP','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.
95+
**isAlpha(str [, locale, options])** | check if the string contains only letters (a-zA-Z).<br/><br/>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', 'ko-KR', 'ja-JP', '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.
96+
**isAlphanumeric(str [, locale, options])** | check if the string contains only letters and numbers (a-zA-Z0-9).<br/><br/>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', 'ko-KR', 'ja-JP','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.
9797
**isAscii(str)** | check if the string contains ASCII chars only.
9898
**isBase32(str [, options])** | check if a string is base32 encoded. `options` is optional and defaults to `{crockford: false}`.<br/> When `crockford` is true it tests the given base32 encoded string using [Crockford's base32 alternative](http://www.crockford.com/base32.html).
9999
**isBase58(str)** | check if a string is base58 encoded.

src/lib/alpha.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const alpha = {
2828
'tr-TR': /^[A-ZÇĞİıÖŞÜ]+$/i,
2929
'uk-UA': /^[А-ЩЬЮЯЄIЇҐі]+$/i,
3030
'vi-VN': /^[A-ZÀÁÃÂĂĐÈÉÊÌÍĨÒÓÕÔƠÙÚŨƯÝ]+$/i,
31+
'ko-KR': /^[---]*$/,
3132
'ku-IQ': /^[ئابپتجچحخدرڕزژسشعغفڤقکگلڵمنوۆھەیێيطؤثآإأكضصةظذ]+$/i,
3233
ar: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/,
3334
he: /^[א-ת]+$/,
@@ -65,6 +66,7 @@ export const alphanumeric = {
6566
'th-TH': /^[-\s]+$/i,
6667
'tr-TR': /^[0-9A-ZÇĞİıÖŞÜ]+$/i,
6768
'uk-UA': /^[0-9А-ЩЬЮЯЄIЇҐі]+$/i,
69+
'ko-KR': /^[0-9---]*$/,
6870
'ku-IQ': /^[٠١٢٣٤٥٦٧٨٩0-9ئابپتجچحخدرڕزژسشعغفڤقکگلڵمنوۆھەیێيطؤثآإأكضصةظذ]+$/i,
6971
'vi-VN': /^[0-9A-ZÀÁÃÂĂĐÈÉÊÌÍĨÒÓÕÔƠÙÚŨƯÝ]+$/i,
7072
ar: /^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/,

test/validators.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,6 +2011,27 @@ describe('Validators', () => {
20112011
});
20122012
});
20132013

2014+
it('should validate Korea alpha strings', () => {
2015+
test({
2016+
validator: 'isAlpha',
2017+
args: ['ko-KR'],
2018+
valid: [
2019+
'ㄱ',
2020+
'ㅑ',
2021+
'ㄱㄴㄷㅏㅕ',
2022+
'세종대왕',
2023+
'나랏말싸미듕귁에달아문자와로서르사맛디아니할쎄',
2024+
],
2025+
invalid: [
2026+
'abc',
2027+
'123',
2028+
'흥선대원군 문호개방',
2029+
'1592년임진왜란',
2030+
'대한민국!',
2031+
],
2032+
});
2033+
});
2034+
20142035
it('should validate Sinhala alpha strings', () => {
20152036
test({
20162037
validator: 'isAlpha',
@@ -2659,6 +2680,23 @@ describe('Validators', () => {
26592680
});
26602681
});
26612682

2683+
it('should validate Korea alphanumeric strings', () => {
2684+
test({
2685+
validator: 'isAlphanumeric',
2686+
args: ['ko-KR'],
2687+
valid: [
2688+
'2002',
2689+
'훈민정음',
2690+
'1446년훈민정음반포',
2691+
],
2692+
invalid: [
2693+
'2022!',
2694+
'2019 코로나시작',
2695+
'1.로렘입숨',
2696+
],
2697+
});
2698+
});
2699+
26622700
it('should validate Sinhala alphanumeric strings', () => {
26632701
test({
26642702
validator: 'isAlphanumeric',

0 commit comments

Comments
 (0)