Skip to content

Commit c6905f5

Browse files
committed
feat(isAlpha, isAlphanumeric): add Japanese locale(ja-JP)
1 parent 1bb14e8 commit c6905f5

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

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', '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', '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', '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.
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
@@ -11,6 +11,7 @@ export const alpha = {
1111
'fi-FI': /^[A-ZÅÄÖ]+$/i,
1212
'fr-FR': /^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
1313
'it-IT': /^[A-ZÀÉÈÌÎÓÒÙ]+$/i,
14+
'ja-JP': /^[----]+$/i,
1415
'nb-NO': /^[A-ZÆØÅ]+$/i,
1516
'nl-NL': /^[A-ZÁÉËÏÓÖÜÚ]+$/i,
1617
'nn-NO': /^[A-ZÆØÅ]+$/i,
@@ -48,6 +49,7 @@ export const alphanumeric = {
4849
'fi-FI': /^[0-9A-ZÅÄÖ]+$/i,
4950
'fr-FR': /^[0-9A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
5051
'it-IT': /^[0-9A-ZÀÉÈÌÎÓÒÙ]+$/i,
52+
'ja-JP': /^[0-9-----]+$/i,
5153
'hu-HU': /^[0-9A-ZÁÉÍÓÖŐÚÜŰ]+$/i,
5254
'nb-NO': /^[0-9A-ZÆØÅ]+$/i,
5355
'nl-NL': /^[0-9A-ZÁÉËÏÓÖÜÚ]+$/i,

test/validators.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,6 +1603,32 @@ describe('Validators', () => {
16031603
});
16041604
});
16051605

1606+
it('should validate Japanese alpha strings', () => {
1607+
test({
1608+
validator: 'isAlpha',
1609+
args: ['ja-JP'],
1610+
valid: [
1611+
'あいうえお',
1612+
'がぎぐげご',
1613+
'ぁぃぅぇぉ',
1614+
'アイウエオ',
1615+
'ァィゥェ',
1616+
'アイウエオ',
1617+
'吾輩は猫である',
1618+
'臥薪嘗胆',
1619+
'新世紀エヴァンゲリオン',
1620+
'天国と地獄',
1621+
'七人の侍',
1622+
'シン・ウルトラマン',
1623+
],
1624+
invalid: [
1625+
'あいう123',
1626+
'abcあいう',
1627+
'1984',
1628+
],
1629+
});
1630+
});
1631+
16061632
it('should validate Vietnamese alpha strings', () => {
16071633
test({
16081634
validator: 'isAlpha',
@@ -2389,6 +2415,28 @@ describe('Validators', () => {
23892415
});
23902416
});
23912417

2418+
it('should validate Japanese alphanumeric strings', () => {
2419+
test({
2420+
validator: 'isAlphanumeric',
2421+
args: ['ja-JP'],
2422+
valid: [
2423+
'あいうえお123',
2424+
'123がぎぐげご',
2425+
'ぁぃぅぇぉ',
2426+
'アイウエオ',
2427+
'ァィゥェ',
2428+
'アイウエオ',
2429+
'20世紀少年',
2430+
'華氏451度',
2431+
],
2432+
invalid: [
2433+
' あいう123 ',
2434+
'abcあいう',
2435+
'生きろ!!',
2436+
],
2437+
});
2438+
});
2439+
23922440
it('should validate kurdish alphanumeric strings', () => {
23932441
test({
23942442
validator: 'isAlphanumeric',

0 commit comments

Comments
 (0)