diff --git a/README.md b/README.md index 7c8887ed3..1b4b4baa6 100644 --- a/README.md +++ b/README.md @@ -91,9 +91,9 @@ 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', '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. -**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', '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. +**isAfter(str [, options])** | check if the string is a date that's after the specified date.

`options` is an object that defaults to `{ date: new Date() }`.
_Options:_
`date`: Date to compare to. Defaults to `new Date()` (now). +**isAlpha(str [, options])** | check if the string contains only letters (a-zA-Z).

`options` is an object that defaults to `{ locale: 'en-US' }`.

**Options:**
`locale`: The supported 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`. The locale list is `validator.isAlphaLocales`.

`ignore`: (optional) A string or RegExp containing characters to ignore, e.g. `'- /' ` or `/[\s/-]/g` to ignore spaces and "-". +**isAlphanumeric(str [, options])** | check if the string contains only letters and numbers (a-zA-Z0-9).

`options` is an object that defaults to `{ locale: 'en-US' }`.

**Options:**
`locale`: The supported 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`. The locale list is `validator.isAlphanumericLocales`.

`ignore`: (optional) A string or RegExp containing characters to ignore, e.g. `'- /' ` or `/[\s/-]/g` to ignore spaces and "-". **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/package.json b/package.json index 7d505205e..13768746f 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "build:node": "babel src -d .", "build": "run-p build:*", "pretest": "npm run build && npm run lint", - "test": "nyc --reporter=cobertura --reporter=text-summary mocha --require @babel/register --reporter dot" + "test": "nyc --reporter=cobertura --reporter=text-summary mocha --require @babel/register --reporter dot --recursive" }, "engines": { "node": ">= 0.10" diff --git a/src/lib/alpha.js b/src/lib/alpha.js index 0535e50d1..48a99b94c 100644 --- a/src/lib/alpha.js +++ b/src/lib/alpha.js @@ -1,3 +1,5 @@ +import assertString from './util/assertString'; + export const alpha = { 'en-US': /^[A-Z]+$/i, 'az-AZ': /^[A-VXYZÇƏĞİıÖŞÜ]+$/i, @@ -83,7 +85,7 @@ export const decimal = { }; -export const englishLocales = ['AU', 'GB', 'HK', 'IN', 'NZ', 'ZA', 'ZM']; +const englishLocales = ['AU', 'GB', 'HK', 'IN', 'NZ', 'ZA', 'ZM']; for (let locale, i = 0; i < englishLocales.length; i++) { locale = `en-${englishLocales[i]}`; @@ -93,7 +95,7 @@ for (let locale, i = 0; i < englishLocales.length; i++) { } // Source: http://www.localeplanet.com/java/ -export const arabicLocales = ['AE', 'BH', 'DZ', 'EG', 'IQ', 'JO', 'KW', 'LB', 'LY', +const arabicLocales = ['AE', 'BH', 'DZ', 'EG', 'IQ', 'JO', 'KW', 'LB', 'LY', 'MA', 'QM', 'QA', 'SA', 'SD', 'SY', 'TN', 'YE']; for (let locale, i = 0; i < arabicLocales.length; i++) { @@ -103,7 +105,7 @@ for (let locale, i = 0; i < arabicLocales.length; i++) { decimal[locale] = decimal.ar; } -export const farsiLocales = ['IR', 'AF']; +const farsiLocales = ['IR', 'AF']; for (let locale, i = 0; i < farsiLocales.length; i++) { locale = `fa-${farsiLocales[i]}`; @@ -111,7 +113,7 @@ for (let locale, i = 0; i < farsiLocales.length; i++) { decimal[locale] = decimal.ar; } -export const bengaliLocales = ['BD', 'IN']; +const bengaliLocales = ['BD', 'IN']; for (let locale, i = 0; i < bengaliLocales.length; i++) { locale = `bn-${bengaliLocales[i]}`; @@ -121,8 +123,8 @@ for (let locale, i = 0; i < bengaliLocales.length; i++) { } // Source: https://en.wikipedia.org/wiki/Decimal_mark -export const dotDecimal = ['ar-EG', 'ar-LB', 'ar-LY']; -export const commaDecimal = [ +const dotDecimal = ['ar-EG', 'ar-LB', 'ar-LY']; +const commaDecimal = [ 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-ZM', 'es-ES', 'fr-CA', 'fr-FR', 'id-ID', 'it-IT', 'ku-IQ', 'hi-IN', 'hu-HU', 'nb-NO', 'nn-NO', 'nl-NL', 'pl-PL', 'pt-PT', 'ru-RU', 'si-LK', 'sl-SI', 'sr-RS@latin', 'sr-RS', 'sv-SE', 'tr-TR', 'uk-UA', 'vi-VN', @@ -150,3 +152,49 @@ decimal['pl-Pl'] = decimal['pl-PL']; // see #1455 alpha['fa-AF'] = alpha.fa; + + +function removeIgnoredCharacters(str, ignoredCharacters) { + if (!ignoredCharacters) { + return str; + } + + if (ignoredCharacters instanceof RegExp) { + return str.replace(ignoredCharacters, ''); + } + + if (typeof ignoredCharacters === 'string') { + return str.replace(new RegExp(`[${ignoredCharacters.replace(/[-[\]{}()*+?.,\\^$|#\\s]/g, '\\$&')}]`, 'g'), ''); // escape regex for 'ignoredCharacters' + } + + throw new Error('"ignore" should be instance of a String or RegExp'); +} + +const ALPHA_TYPE_MAP = { + alpha, + alphanumeric, +}; + +function validate(typeKey) { + return (_str, ...args) => { + assertString(_str); + + // For backwards compatibility: + // isAlpha | isAlphaNumeric(str [, locale, options]) + // i.e. `options` could be used as argument for the legacy `locale` + const locale = (typeof args[0] === 'object' ? args[0].locale : args[0]) || 'en-US'; + const ignore = (typeof args[0] === 'object' ? args[0].ignore : args[1]?.ignore); + + const str = removeIgnoredCharacters(_str, ignore); + const alphaType = ALPHA_TYPE_MAP[typeKey]; + + if (alphaType[locale]) { + return alphaType[locale].test(str); + } + + throw new Error(`Invalid "locale" '${locale}'`); + }; +} + +export const isAlpha = validate('alpha'); +export const isAlphanumeric = validate('alphanumeric'); diff --git a/src/lib/isAfter.js b/src/lib/isAfter.js index 47bfb537f..24d18fa25 100644 --- a/src/lib/isAfter.js +++ b/src/lib/isAfter.js @@ -1,8 +1,13 @@ import assertString from './util/assertString'; import toDate from './toDate'; -export default function isAfter(str, date = String(new Date())) { +export default function isAfter(str, options) { assertString(str); + + // accessing 'arguments' for backwards compatibility: isAfter(str [, date]) + // eslint-disable-next-line prefer-rest-params + const date = (typeof options === 'object' ? options.date : arguments[1]) || Date().toString(); + const comparison = toDate(date); const original = toDate(str); return !!(original && comparison && original > comparison); diff --git a/src/lib/isAlpha.js b/src/lib/isAlpha.js index e961e64eb..c5dafc52c 100644 --- a/src/lib/isAlpha.js +++ b/src/lib/isAlpha.js @@ -1,26 +1,5 @@ -import assertString from './util/assertString'; -import { alpha } from './alpha'; +import { alpha, isAlpha } from './alpha'; -export default function isAlpha(_str, locale = 'en-US', options = {}) { - assertString(_str); - - let str = _str; - const { ignore } = options; - - if (ignore) { - if (ignore instanceof RegExp) { - str = str.replace(ignore, ''); - } else if (typeof ignore === 'string') { - str = str.replace(new RegExp(`[${ignore.replace(/[-[\]{}()*+?.,\\^$|#\\s]/g, '\\$&')}]`, 'g'), ''); // escape regex for ignore - } else { - throw new Error('ignore should be instance of a String or RegExp'); - } - } - - if (locale in alpha) { - return alpha[locale].test(str); - } - throw new Error(`Invalid locale '${locale}'`); -} +export default isAlpha; export const locales = Object.keys(alpha); diff --git a/src/lib/isAlphanumeric.js b/src/lib/isAlphanumeric.js index b259ab908..15ce0bad1 100644 --- a/src/lib/isAlphanumeric.js +++ b/src/lib/isAlphanumeric.js @@ -1,26 +1,5 @@ -import assertString from './util/assertString'; -import { alphanumeric } from './alpha'; +import { alphanumeric, isAlphanumeric } from './alpha'; -export default function isAlphanumeric(_str, locale = 'en-US', options = {}) { - assertString(_str); - - let str = _str; - const { ignore } = options; - - if (ignore) { - if (ignore instanceof RegExp) { - str = str.replace(ignore, ''); - } else if (typeof ignore === 'string') { - str = str.replace(new RegExp(`[${ignore.replace(/[-[\]{}()*+?.,\\^$|#\\s]/g, '\\$&')}]`, 'g'), ''); // escape regex for ignore - } else { - throw new Error('ignore should be instance of a String or RegExp'); - } - } - - if (locale in alphanumeric) { - return alphanumeric[locale].test(str); - } - throw new Error(`Invalid locale '${locale}'`); -} +export default isAlphanumeric; export const locales = Object.keys(alphanumeric); diff --git a/test/client-side.js b/test/client-side.test.js similarity index 100% rename from test/client-side.js rename to test/client-side.test.js diff --git a/test/exports.js b/test/exports.test.js similarity index 100% rename from test/exports.js rename to test/exports.test.js diff --git a/test/sanitizers.js b/test/sanitizers.test.js similarity index 100% rename from test/sanitizers.js rename to test/sanitizers.test.js diff --git a/test/testFunctions.js b/test/testFunctions.js new file mode 100644 index 000000000..833dc6572 --- /dev/null +++ b/test/testFunctions.js @@ -0,0 +1,60 @@ +import assert from 'assert'; +import { format } from 'util'; +import validator from '../src/index'; + +function test(options) { + const args = options.args || []; + + args.unshift(null); + + if (options.error) { + options.error.forEach((error) => { + args[0] = error; + + try { + assert.throws(() => validator[options.validator](...args)); + } catch (err) { + const warning = format( + 'validator.%s(%s) passed but should error', + options.validator, args.join(', ') + ); + + throw new Error(warning); + } + }); + } + + if (options.valid) { + options.valid.forEach((valid) => { + args[0] = valid; + + if (validator[options.validator](...args) !== true) { + const warning = format( + 'validator.%s(%s) failed but should have passed', + options.validator, args.join(', ') + ); + + throw new Error(warning); + } + }); + } + + if (options.invalid) { + options.invalid.forEach((invalid) => { + args[0] = invalid; + + if (validator[options.validator](...args) !== false) { + const warning = format( + 'validator.%s(%s) passed but should have failed', + options.validator, args.join(', ') + ); + + throw new Error(warning); + } + }); + } +} + +export default { + test, +}; diff --git a/test/util.js b/test/util.test.js similarity index 100% rename from test/util.js rename to test/util.test.js diff --git a/test/validators.js b/test/validators.test.js similarity index 88% rename from test/validators.js rename to test/validators.test.js index c0e36bec7..d33abfc44 100644 --- a/test/validators.js +++ b/test/validators.test.js @@ -3,60 +3,10 @@ import fs from 'fs'; import { format } from 'util'; import vm from 'vm'; import validator from '../src/index'; +import { test } from './testFunctions'; let validator_js = fs.readFileSync(require.resolve('../validator.js')).toString(); -function test(options) { - let args = options.args || []; - args.unshift(null); - if (options.error) { - options.error.forEach((error) => { - args[0] = error; - try { - assert.throws(() => validator[options.validator](...args)); - } catch (err) { - let warning = format( - 'validator.%s(%s) passed but should error', - options.validator, args.join(', ') - ); - throw new Error(warning); - } - }); - } - if (options.valid) { - options.valid.forEach((valid) => { - args[0] = valid; - if (validator[options.validator](...args) !== true) { - let warning = format( - 'validator.%s(%s) failed but should have passed', - options.validator, args.join(', ') - ); - throw new Error(warning); - } - }); - } - if (options.invalid) { - options.invalid.forEach((invalid) => { - args[0] = invalid; - if (validator[options.validator](...args) !== false) { - let warning = format( - 'validator.%s(%s) passed but should have failed', - options.validator, args.join(', ') - ); - throw new Error(warning); - } - }); - } -} - -function repeat(str, count) { - let result = ''; - for (; count; count--) { - result += str; - } - return result; -} - describe('Validators', () => { it('should validate email addresses', () => { test({ @@ -74,9 +24,9 @@ describe('Validators', () => { '"foobar"@example.com', '" foo m端ller "@example.com', '"foo\\@bar"@example.com', - `${repeat('a', 64)}@${repeat('a', 63)}.com`, - `${repeat('a', 64)}@${repeat('a', 63)}.com`, - `${repeat('a', 31)}@gmail.com`, + `${'a'.repeat(64)}@${'a'.repeat(63)}.com`, + `${'a'.repeat(64)}@${'a'.repeat(63)}.com`, + `${'a'.repeat(31)}@gmail.com`, 'test@gmail.com', 'test.1@gmail.com', 'test@1337.com', @@ -90,10 +40,10 @@ describe('Validators', () => { 'foo@bar.co.uk.', 'z@co.c', 'gmailgmailgmailgmailgmail@gmail.com', - `${repeat('a', 64)}@${repeat('a', 251)}.com`, - `${repeat('a', 65)}@${repeat('a', 250)}.com`, - `${repeat('a', 64)}@${repeat('a', 64)}.com`, - `${repeat('a', 64)}@${repeat('a', 63)}.${repeat('a', 63)}.${repeat('a', 63)}.${repeat('a', 58)}.com`, + `${'a'.repeat(64)}@${'a'.repeat(251)}.com`, + `${'a'.repeat(65)}@${'a'.repeat(250)}.com`, + `${'a'.repeat(64)}@${'a'.repeat(64)}.com`, + `${'a'.repeat(64)}@${'a'.repeat(63)}.${'a'.repeat(63)}.${'a'.repeat(63)}.${'a'.repeat(58)}.com`, 'test1@invalid.co m', 'test2@invalid.co m', 'test3@invalid.co m', @@ -128,10 +78,10 @@ describe('Validators', () => { 'foobar@gmail.com', 'foo.bar@gmail.com', 'foo.bar@googlemail.com', - `${repeat('a', 30)}@gmail.com`, + `${'a'.repeat(30)}@gmail.com`, ], invalid: [ - `${repeat('a', 31)}@gmail.com`, + `${'a'.repeat(31)}@gmail.com`, 'test@gmail.com', 'test.1@gmail.com', '.foobar@gmail.com', @@ -1079,1652 +1029,261 @@ describe('Validators', () => { '1:1:1:1:1:1:1:1:1:1:1:1:1:1:1:1', '::11111', '11111:1:1:1:1:1:1:1', - '2001:db8:0000:1:1:1:1::1', - '0:0:0:0:0:0:ffff:127.0.0.1', - '0:0:0:0:ffff:127.0.0.1', - ], - }); - test({ - validator: 'isIP', - args: [4], - valid: [ - '127.0.0.1', - '0.0.0.0', - '255.255.255.255', - '1.2.3.4', - '255.0.0.1', - '0.0.1.1', - ], - invalid: [ - '::1', - '2001:db8:0000:1:1:1:1:1', - '::ffff:127.0.0.1', - '137.132.10.01', - '0.256.0.256', - '255.256.255.256', - ], - }); - test({ - validator: 'isIP', - args: [6], - valid: [ - '::1', - '2001:db8:0000:1:1:1:1:1', - '::ffff:127.0.0.1', - 'fe80::1234%1', - 'ff08::9abc%10', - 'ff08::9abc%interface10', - 'ff02::5678%pvc1.3', - ], - invalid: [ - '127.0.0.1', - '0.0.0.0', - '255.255.255.255', - '1.2.3.4', - '::ffff:287.0.0.1', - '%', - 'fe80::1234%', - 'fe80::1234%1%3%4', - 'fe80%fe80%', - ], - }); - test({ - validator: 'isIP', - args: [10], - valid: [], - invalid: [ - '127.0.0.1', - '0.0.0.0', - '255.255.255.255', - '1.2.3.4', - '::1', - '2001:db8:0000:1:1:1:1:1', - ], - }); - }); - - it('should validate isIPRange', () => { - test({ - validator: 'isIPRange', - valid: [ - '127.0.0.1/24', - '0.0.0.0/0', - '255.255.255.0/32', - '::/0', - '::/128', - '2001::/128', - '2001:800::/128', - '::ffff:127.0.0.1/128', - ], - invalid: [ - 'abc', - '127.200.230.1/35', - '127.200.230.1/-1', - '1.1.1.1/011', - '1.1.1/24.1', - '1.1.1.1/01', - '1.1.1.1/1.1', - '1.1.1.1/1.', - '1.1.1.1/1/1', - '1.1.1.1', - '::1', - '::1/164', - '2001::/240', - '2001::/-1', - '2001::/001', - '2001::/24.1', - '2001:db8:0000:1:1:1:1:1', - '::ffff:127.0.0.1', - ], - }); - test({ - validator: 'isIPRange', - args: [4], - valid: [ - '127.0.0.1/1', - '0.0.0.0/1', - '255.255.255.255/1', - '1.2.3.4/1', - '255.0.0.1/1', - '0.0.1.1/1', - ], - invalid: [ - 'abc', - '::1', - '2001:db8:0000:1:1:1:1:1', - '::ffff:127.0.0.1', - '137.132.10.01', - '0.256.0.256', - '255.256.255.256', - ], - }); - test({ - validator: 'isIPRange', - args: [6], - valid: [ - '::1/1', - '2001:db8:0000:1:1:1:1:1/1', - '::ffff:127.0.0.1/1', - ], - invalid: [ - 'abc', - '127.0.0.1', - '0.0.0.0', - '255.255.255.255', - '1.2.3.4', - '::ffff:287.0.0.1', - '::ffff:287.0.0.1/254', - '%', - 'fe80::1234%', - 'fe80::1234%1%3%4', - 'fe80%fe80%', - ], - }); - test({ - validator: 'isIPRange', - args: [10], - valid: [], - invalid: [ - 'abc', - '127.0.0.1/1', - '0.0.0.0/1', - '255.255.255.255/1', - '1.2.3.4/1', - '::1/1', - '2001:db8:0000:1:1:1:1:1/1', - ], - }); - }); - - it('should validate FQDN', () => { - test({ - validator: 'isFQDN', - valid: [ - 'domain.com', - 'dom.plato', - 'a.domain.co', - 'foo--bar.com', - 'xn--froschgrn-x9a.com', - 'rebecca.blackfriday', - '1337.com', - ], - invalid: [ - 'abc', - '256.0.0.0', - '_.com', - '*.some.com', - 's!ome.com', - 'domain.com/', - '/more.com', - 'domain.com�', - 'domain.co\u00A0m', - 'domain.co\u1680m', - 'domain.co\u2006m', - 'domain.co\u2028m', - 'domain.co\u2029m', - 'domain.co\u202Fm', - 'domain.co\u205Fm', - 'domain.co\u3000m', - 'domain.com\uDC00', - 'domain.co\uEFFFm', - 'domain.co\uFDDAm', - 'domain.co\uFFF4m', - 'domain.com©', - 'example.0', - '192.168.0.9999', - '192.168.0', - ], - }); - }); - it('should validate FQDN with trailing dot option', () => { - test({ - validator: 'isFQDN', - args: [ - { allow_trailing_dot: true }, - ], - valid: [ - 'example.com.', - ], - }); - }); - it('should invalidate FQDN when not require_tld', () => { - test({ - validator: 'isFQDN', - args: [ - { require_tld: false }, - ], - invalid: [ - 'example.0', - '192.168.0', - '192.168.0.9999', - ], - }); - }); - it('should validate FQDN when not require_tld but allow_numeric_tld', () => { - test({ - validator: 'isFQDN', - args: [ - { allow_numeric_tld: true, require_tld: false }, - ], - valid: [ - 'example.0', - '192.168.0', - '192.168.0.9999', - ], - }); - }); - it('should validate FQDN with wildcard option', () => { - test({ - validator: 'isFQDN', - args: [ - { allow_wildcard: true }, - ], - valid: [ - '*.example.com', - '*.shop.example.com', - ], - }); - }); - it('should validate FQDN with required allow_trailing_dot, allow_underscores and allow_numeric_tld options', () => { - test({ - validator: 'isFQDN', - args: [ - { allow_trailing_dot: true, allow_underscores: true, allow_numeric_tld: true }, - ], - valid: [ - 'abc.efg.g1h.', - 'as1s.sad3s.ssa2d.', - ], - }); - }); - it('should validate alpha strings', () => { - test({ - validator: 'isAlpha', - valid: [ - 'abc', - 'ABC', - 'FoObar', - ], - invalid: [ - 'abc1', - ' foo ', - '', - 'ÄBC', - 'FÜübar', - 'Jön', - 'Heiß', - ], - }); - }); - - it('should validate alpha string with ignored characters', () => { - test({ - validator: 'isAlpha', - args: ['en-US', { ignore: '- /' }], // ignore [space-/] - valid: [ - 'en-US', - 'this is a valid alpha string', - 'us/usa', - ], - invalid: [ - '1. this is not a valid alpha string', - 'this$is also not a valid.alpha string', - 'this is also not a valid alpha string.', - ], - }); - - test({ - validator: 'isAlpha', - args: ['en-US', { ignore: /[\s/-]/g }], // ignore [space -] - valid: [ - 'en-US', - 'this is a valid alpha string', - ], - invalid: [ - '1. this is not a valid alpha string', - 'this$is also not a valid.alpha string', - 'this is also not a valid alpha string.', - ], - }); - - test({ - validator: 'isAlpha', - args: ['en-US', { ignore: 1234 }], // invalid ignore matcher - error: [ - 'alpha', - ], - }); - }); - - 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', - args: ['bg-BG'], - valid: [ - 'абв', - 'АБВ', - 'жаба', - 'яГоДа', - ], - invalid: [ - 'abc1', - ' foo ', - '', - 'ЁЧПС', - '_аз_обичам_обувки_', - 'ехо!', - ], - }); - }); - - it('should validate Bengali alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['bn-BD'], - valid: [ - 'অয়াওর', - 'ফগফদ্রত', - 'ফদ্ম্যতভ', - 'বেরেওভচনভন', - 'আমারবাসগা', - ], - invalid: [ - 'দাস২৩৪', - ' দ্গফহ্নভ ', - '', - '(গফদ)', - ], - }); - }); - - it('should validate czech alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['cs-CZ'], - valid: [ - 'žluťoučký', - 'KŮŇ', - 'Pěl', - 'Ďábelské', - 'ódy', - ], - invalid: [ - 'ábc1', - ' fůj ', - '', - ], - }); - }); - - it('should validate slovak alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['sk-SK'], - valid: [ - 'môj', - 'ľúbím', - 'mäkčeň', - 'stĹp', - 'vŕba', - 'ňorimberk', - 'ťava', - 'žanéta', - 'Ďábelské', - 'ódy', - ], - invalid: [ - '1moj', - '你好世界', - ' Привет мир ', - 'مرحبا العا ', - ], - }); - }); - - it('should validate danish alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['da-DK'], - valid: [ - 'aøå', - 'Ære', - 'Øre', - 'Åre', - ], - invalid: [ - 'äbc123', - 'ÄBC11', - '', - ], - }); - }); - - it('should validate dutch alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['nl-NL'], - valid: [ - 'Kán', - 'één', - 'vóór', - 'nú', - 'héél', - ], - invalid: [ - 'äca ', - 'abcß', - 'Øre', - ], - }); - }); - - it('should validate german alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['de-DE'], - valid: [ - 'äbc', - 'ÄBC', - 'FöÖbär', - 'Heiß', - ], - invalid: [ - 'äbc1', - ' föö ', - '', - ], - }); - }); - - it('should validate hungarian alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['hu-HU'], - valid: [ - 'árvíztűrőtükörfúrógép', - 'ÁRVÍZTŰRŐTÜKÖRFÚRÓGÉP', - ], - invalid: [ - 'äbc1', - ' fäö ', - 'Heiß', - '', - ], - }); - }); - - it('should validate portuguese alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['pt-PT'], - valid: [ - 'palíndromo', - 'órgão', - 'qwértyúão', - 'àäãcëüïÄÏÜ', - ], - invalid: [ - '12abc', - 'Heiß', - 'Øre', - 'æøå', - '', - ], - }); - }); - - it('should validate italian alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['it-IT'], - valid: [ - 'àéèìîóòù', - 'correnti', - 'DEFINIZIONE', - 'compilazione', - 'metró', - 'pèsca', - 'PÉSCA', - 'genî', - ], - invalid: [ - 'äbc123', - 'ÄBC11', - 'æøå', - '', - ], - }); - }); - - it('should validate Japanese alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['ja-JP'], - valid: [ - 'あいうえお', - 'がぎぐげご', - 'ぁぃぅぇぉ', - 'アイウエオ', - 'ァィゥェ', - 'アイウエオ', - '吾輩は猫である', - '臥薪嘗胆', - '新世紀エヴァンゲリオン', - '天国と地獄', - '七人の侍', - 'シン・ウルトラマン', - ], - invalid: [ - 'あいう123', - 'abcあいう', - '1984', - ], - }); - }); - - it('should validate Vietnamese alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['vi-VN'], - valid: [ - 'thiến', - 'nghiêng', - 'xin', - 'chào', - 'thế', - 'giới', - ], - invalid: [ - 'thầy3', - 'Ba gà', - '', - ], - }); - }); - - it('should validate arabic alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['ar'], - valid: [ - 'أبت', - 'اَبِتَثّجً', - ], - invalid: [ - '١٢٣أبت', - '١٢٣', - 'abc1', - ' foo ', - '', - 'ÄBC', - 'FÜübar', - 'Jön', - 'Heiß', - ], - }); - }); - - it('should validate farsi alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['fa-IR'], - valid: [ - 'پدر', - 'مادر', - 'برادر', - 'خواهر', - ], - invalid: [ - 'فارسی۱۲۳', - '۱۶۴', - 'abc1', - ' foo ', - '', - 'ÄBC', - 'FÜübar', - 'Jön', - 'Heiß', - ], - }); - }); - - it('should validate finnish alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['fi-FI'], - valid: [ - 'äiti', - 'Öljy', - 'Åke', - 'testÖ', - ], - invalid: [ - 'AİıÖöÇ窺ĞğÜüZ', - 'äöå123', - '', - ], - }); - }); - - it('should validate kurdish alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['ku-IQ'], - valid: [ - 'ئؤڤگێ', - 'کوردستان', - ], - invalid: [ - 'ئؤڤگێ١٢٣', - '١٢٣', - 'abc1', - ' foo ', - '', - 'ÄBC', - 'FÜübar', - 'Jön', - 'Heiß', - ], - }); - }); - - it('should validate norwegian alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['nb-NO'], - valid: [ - 'aøå', - 'Ære', - 'Øre', - 'Åre', - ], - invalid: [ - 'äbc123', - 'ÄBC11', - '', - ], - }); - }); - - it('should validate polish alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['pl-PL'], - valid: [ - 'kreską', - 'zamknięte', - 'zwykłe', - 'kropką', - 'przyjęły', - 'święty', - 'Pozwól', - ], - invalid: [ - '12řiď ', - 'blé!!', - 'föö!2!', - ], - }); - }); - - it('should validate serbian cyrillic alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['sr-RS'], - valid: [ - 'ШћжЂљЕ', - 'ЧПСТЋЏ', - ], - invalid: [ - 'řiď ', - 'blé33!!', - 'föö!!', - ], - }); - }); - - it('should validate serbian latin alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['sr-RS@latin'], - valid: [ - 'ŠAabčšđćž', - 'ŠATROĆčđš', - ], - invalid: [ - '12řiď ', - 'blé!!', - 'föö!2!', - ], - }); - }); - - it('should validate spanish alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['es-ES'], - valid: [ - 'ábcó', - 'ÁBCÓ', - 'dormís', - 'volvés', - 'español', - ], - invalid: [ - 'äca ', - 'abcß', - 'föö!!', - ], - }); - }); - - it('should validate swedish alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['sv-SE'], - valid: [ - 'religiös', - 'stjäla', - 'västgöte', - 'Åre', - ], - invalid: [ - 'AİıÖöÇ窺ĞğÜüZ', - 'religiös23', - '', - ], - }); - }); - - it('should validate defined arabic locales alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['ar-SY'], - valid: [ - 'أبت', - 'اَبِتَثّجً', - ], - invalid: [ - '١٢٣أبت', - '١٢٣', - 'abc1', - ' foo ', - '', - 'ÄBC', - 'FÜübar', - 'Jön', - 'Heiß', - ], - }); - }); - - it('should validate turkish alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['tr-TR'], - valid: [ - 'AİıÖöÇ窺ĞğÜüZ', - ], - invalid: [ - '0AİıÖöÇ窺ĞğÜüZ1', - ' AİıÖöÇ窺ĞğÜüZ ', - 'abc1', - ' foo ', - '', - 'ÄBC', - 'Heiß', - ], - }); - }); - - it('should validate urkrainian alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['uk-UA'], - valid: [ - 'АБВГҐДЕЄЖЗИIЇЙКЛМНОПРСТУФХЦШЩЬЮЯ', - ], - invalid: [ - '0AİıÖöÇ窺ĞğÜüZ1', - ' AİıÖöÇ窺ĞğÜüZ ', - 'abc1', - ' foo ', - '', - 'ÄBC', - 'Heiß', - 'ЫыЪъЭэ', - ], - }); - }); - - it('should validate greek alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['el-GR'], - valid: [ - 'αβγδεζηθικλμνξοπρςστυφχψω', - 'ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ', - 'άέήίΰϊϋόύώ', - 'ΆΈΉΊΪΫΎΏ', - ], - invalid: [ - '0AİıÖöÇ窺ĞğÜüZ1', - ' AİıÖöÇ窺ĞğÜüZ ', - 'ÄBC', - 'Heiß', - 'ЫыЪъЭэ', - '120', - 'jαckγ', - ], - }); - }); - - it('should validate Hebrew alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['he'], - valid: [ - 'בדיקה', - 'שלום', - ], - invalid: [ - 'בדיקה123', - ' foo ', - 'abc1', - '', - ], - }); - }); - - it('should validate Hindi alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['hi-IN'], - valid: [ - 'अतअपनाअपनीअपनेअभीअंदरआदिआपइत्यादिइनइनकाइन्हींइन्हेंइन्होंइसइसकाइसकीइसकेइसमेंइसीइसेउनउनकाउनकीउनकेउनकोउन्हींउन्हेंउन्होंउसउसकेउसीउसेएकएवंएसऐसेऔरकईकरकरताकरतेकरनाकरनेकरेंकहतेकहाकाकाफ़ीकिकितनाकिन्हेंकिन्होंकियाकिरकिसकिसीकिसेकीकुछकुलकेकोकोईकौनकौनसागयाघरजबजहाँजाजितनाजिनजिन्हेंजिन्होंजिसजिसेजीधरजैसाजैसेजोतकतबतरहतिनतिन्हेंतिन्होंतिसतिसेतोथाथीथेदबारादियादुसरादूसरेदोद्वाराननकेनहींनानिहायतनीचेनेपरपहलेपूरापेफिरबनीबहीबहुतबादबालाबिलकुलभीभीतरमगरमानोमेमेंयदियहयहाँयहीयायिहयेरखेंरहारहेऱ्वासालिएलियेलेकिनववग़ैरहवर्गवहवहाँवहींवालेवुहवेवोसकतासकतेसबसेसभीसाथसाबुतसाभसारासेसोसंगहीहुआहुईहुएहैहैंहोहोताहोतीहोतेहोनाहोने', - 'इन्हें', - ], - invalid: [ - 'अत०२३४५६७८९', - 'अत 12', - ' अत ', - 'abc1', - 'abc', - '', - ], - }); - }); - - it('should validate persian alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['fa-IR'], - valid: [ - 'تست', - 'عزیزم', - 'ح', - ], - invalid: [ - 'تست 1', - ' عزیزم ', - '', - ], - }); - }); - - it('should validate Thai alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['th-TH'], - valid: [ - 'สวัสดี', - 'ยินดีต้อนรับ เทสเคส', - ], - invalid: [ - 'สวัสดีHi', - '123 ยินดีต้อนรับ', - 'ยินดีต้อนรับ-๑๒๓', - ], - }); - }); - - it('should validate Korea alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['ko-KR'], - valid: [ - 'ㄱ', - 'ㅑ', - 'ㄱㄴㄷㅏㅕ', - '세종대왕', - '나랏말싸미듕귁에달아문자와로서르사맛디아니할쎄', - ], - invalid: [ - 'abc', - '123', - '흥선대원군 문호개방', - '1592년임진왜란', - '대한민국!', - ], - }); - }); - - it('should validate Sinhala alpha strings', () => { - test({ - validator: 'isAlpha', - args: ['si-LK'], - valid: [ - 'චතුර', - 'කචටදබ', - 'ඎඏදාෛපසුගො', - ], - invalid: [ - 'ஆஐअतක', - 'කචට 12', - ' ඎ ', - 'abc1', - 'abc', - '', - ], - }); - }); - - it('should error on invalid locale', () => { - test({ - validator: 'isAlpha', - args: ['is-NOT'], - error: [ - 'abc', - 'ABC', - ], - }); - }); - - it('should validate alphanumeric strings', () => { - test({ - validator: 'isAlphanumeric', - valid: [ - 'abc123', - 'ABC11', - ], - invalid: [ - 'abc ', - 'foo!!', - 'ÄBC', - 'FÜübar', - 'Jön', - ], - }); - }); - - it('should validate alphanumeric string with ignored characters', () => { - test({ - validator: 'isAlphanumeric', - args: ['en-US', { ignore: '@_- ' }], // ignore [@ space _ -] - valid: [ - 'Hello@123', - 'this is a valid alphaNumeric string', - 'En-US @ alpha_numeric', - ], - invalid: [ - 'In*Valid', - 'hello$123', - '{invalid}', - ], - }); - - test({ - validator: 'isAlphanumeric', - args: ['en-US', { ignore: /[\s/-]/g }], // ignore [space -] - valid: [ - 'en-US', - 'this is a valid alphaNumeric string', - ], - invalid: [ - 'INVALID$ AlphaNum Str', - 'hello@123', - 'abc*123', - ], - }); - - test({ - validator: 'isAlphanumeric', - args: ['en-US', { ignore: 1234 }], // invalid ignore matcher (ignore should be instance of a String or RegExp) - error: [ - 'alpha', - ], - }); - }); - - it('should validate defined english aliases', () => { - test({ - validator: 'isAlphanumeric', - args: ['en-GB'], - valid: [ - 'abc123', - 'ABC11', - ], - invalid: [ - 'abc ', - 'foo!!', - 'ÄBC', - 'FÜübar', - 'Jön', - ], - }); - }); - - 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', - args: ['bg-BG'], - valid: [ - 'абв1', - '4АБ5В6', - 'жаба', - 'яГоДа2', - 'йЮя', - '123', - ], - invalid: [ - ' ', - '789 ', - 'hello000', - ], - }); - }); - - it('should validate Bengali alphanumeric strings', () => { - test({ - validator: 'isAlphanumeric', - args: ['bn-BD'], - valid: [ - 'দ্গজ্ঞহ্রত্য১২৩', - 'দ্গগফ৮৯০', - 'চব৩৬৫ভবচ', - '১২৩৪', - '৩৪২৩৪দফজ্ঞদফ', - ], - invalid: [ - ' ', - '১২৩ ', - 'hel৩২0', - ], - }); - }); - - it('should validate czech alphanumeric strings', () => { - test({ - validator: 'isAlphanumeric', - args: ['cs-CZ'], - valid: [ - 'řiť123', - 'KŮŇ11', - ], - invalid: [ - 'řiď ', - 'blé!!', - ], - }); - }); - - it('should validate slovak alphanumeric strings', () => { - test({ - validator: 'isAlphanumeric', - args: ['sk-SK'], - valid: [ - '1môj', - '2ľúbím', - '3mäkčeň', - '4stĹp', - '5vŕba', - '6ňorimberk', - '7ťava', - '8žanéta', - '9Ďábelské', - '10ódy', - ], - invalid: [ - '1moj!', - '你好世界', - ' Привет мир ', - ], - }); - }); - - it('should validate danish alphanumeric strings', () => { - test({ - validator: 'isAlphanumeric', - args: ['da-DK'], - valid: [ - 'ÆØÅ123', - 'Ære321', - '321Øre', - '123Åre', - ], - invalid: [ - 'äbc123', - 'ÄBC11', - '', - ], - }); - }); - - it('should validate dutch alphanumeric strings', () => { - test({ - validator: 'isAlphanumeric', - args: ['nl-NL'], - valid: [ - 'Kán123', - 'één354', - 'v4óór', - 'nú234', - 'hé54él', - ], - invalid: [ - '1äca ', - 'ab3cß', - 'Øre', - ], - }); - }); - - it('should validate finnish alphanumeric strings', () => { - test({ - validator: 'isAlphanumeric', - args: ['fi-FI'], - valid: [ - 'äiti124', - 'ÖLJY1234', - '123Åke', - '451åå23', - ], - invalid: [ - 'AİıÖöÇ窺ĞğÜüZ', - 'foo!!', - '', - ], - }); - }); - - it('should validate german alphanumeric strings', () => { - test({ - validator: 'isAlphanumeric', - args: ['de-DE'], - valid: [ - 'äbc123', - 'ÄBC11', - ], - invalid: [ - 'äca ', - 'föö!!', - ], - }); - }); - - it('should validate hungarian alphanumeric strings', () => { - test({ - validator: 'isAlphanumeric', - args: ['hu-HU'], - valid: [ - '0árvíztűrőtükörfúrógép123', - '0ÁRVÍZTŰRŐTÜKÖRFÚRÓGÉP123', - ], - invalid: [ - '1időúr!', - 'äbc1', - ' fäö ', - 'Heiß!', - '', - ], - }); - }); - - it('should validate portuguese alphanumeric strings', () => { - test({ - validator: 'isAlphanumeric', - args: ['pt-PT'], - valid: [ - 'palíndromo', - '2órgão', - 'qwértyúão9', - 'àäãcë4üïÄÏÜ', - ], - invalid: [ - '!abc', - 'Heiß', - 'Øre', - 'æøå', - '', - ], - }); - }); - - it('should validate italian alphanumeric strings', () => { - test({ - validator: 'isAlphanumeric', - args: ['it-IT'], - valid: [ - '123àéèìîóòù', - '123correnti', - 'DEFINIZIONE321', - 'compil123azione', - 'met23ró', - 'pès56ca', - 'PÉS45CA', - 'gen45î', - ], - invalid: [ - 'äbc123', - 'ÄBC11', - 'æøå', - '', - ], - }); - }); - - it('should validate spanish alphanumeric strings', () => { - test({ - validator: 'isAlphanumeric', - args: ['es-ES'], - valid: [ - 'ábcó123', - 'ÁBCÓ11', - ], - invalid: [ - 'äca ', - 'abcß', - 'föö!!', - ], - }); - }); - - it('should validate Vietnamese alphanumeric strings', () => { - test({ - validator: 'isAlphanumeric', - args: ['vi-VN'], - valid: [ - 'Thầy3', - '3Gà', - ], - invalid: [ - 'toang!', - 'Cậu Vàng', - ], - }); - }); - - it('should validate arabic alphanumeric strings', () => { - test({ - validator: 'isAlphanumeric', - args: ['ar'], - valid: [ - 'أبت123', - 'أبتَُِ١٢٣', - ], - invalid: [ - 'äca ', - 'abcß', - 'föö!!', - ], - }); - }); - - it('should validate Hindi alphanumeric strings', () => { - test({ - validator: 'isAlphanumeric', - args: ['hi-IN'], - valid: [ - 'अतअपनाअपनीअपनेअभीअंदरआदिआपइत्यादिइनइनकाइन्हींइन्हेंइन्होंइसइसकाइसकीइसकेइसमेंइसीइसेउनउनकाउनकीउनकेउनकोउन्हींउन्हेंउन्होंउसउसकेउसीउसेएकएवंएसऐसेऔरकईकरकरताकरतेकरनाकरनेकरेंकहतेकहाकाकाफ़ीकिकितनाकिन्हेंकिन्होंकियाकिरकिसकिसीकिसेकीकुछकुलकेकोकोईकौनकौनसागयाघरजबजहाँजाजितनाजिनजिन्हेंजिन्होंजिसजिसेजीधरजैसाजैसेजोतकतबतरहतिनतिन्हेंतिन्होंतिसतिसेतोथाथीथेदबारादियादुसरादूसरेदोद्वाराननकेनहींनानिहायतनीचेनेपरपहलेपूरापेफिरबनीबहीबहुतबादबालाबिलकुलभीभीतरमगरमानोमेमेंयदियहयहाँयहीयायिहयेरखेंरहारहेऱ्वासालिएलियेलेकिनववग़ैरहवर्गवहवहाँवहींवालेवुहवेवोसकतासकतेसबसेसभीसाथसाबुतसाभसारासेसोसंगहीहुआहुईहुएहैहैंहोहोताहोतीहोतेहोनाहोने०२३४५६७८९', - 'इन्हें४५६७८९', - ], - invalid: [ - 'अत ०२३४५६७८९', - ' ३४५६७८९', - '12 ', - ' अत ', - 'abc1', - 'abc', - '', - ], - }); - }); - - it('should validate farsi alphanumeric strings', () => { - test({ - validator: 'isAlphanumeric', - args: ['fa-IR'], - valid: [ - 'پارسی۱۲۳', - '۱۴۵۶', - 'مژگان9', - ], - invalid: [ - 'äca ', - 'abcßة', - 'föö!!', - '٤٥٦', + '2001:db8:0000:1:1:1:1::1', + '0:0:0:0:0:0:ffff:127.0.0.1', + '0:0:0:0:ffff:127.0.0.1', ], }); - }); - - it('should validate Japanese alphanumeric strings', () => { test({ - validator: 'isAlphanumeric', - args: ['ja-JP'], + validator: 'isIP', + args: [4], valid: [ - 'あいうえお123', - '123がぎぐげご', - 'ぁぃぅぇぉ', - 'アイウエオ', - 'ァィゥェ', - 'アイウエオ', - '20世紀少年', - '華氏451度', + '127.0.0.1', + '0.0.0.0', + '255.255.255.255', + '1.2.3.4', + '255.0.0.1', + '0.0.1.1', ], invalid: [ - ' あいう123 ', - 'abcあいう', - '生きろ!!', + '::1', + '2001:db8:0000:1:1:1:1:1', + '::ffff:127.0.0.1', + '137.132.10.01', + '0.256.0.256', + '255.256.255.256', ], }); - }); - - it('should validate kurdish alphanumeric strings', () => { test({ - validator: 'isAlphanumeric', - args: ['ku-IQ'], + validator: 'isIP', + args: [6], valid: [ - 'ئؤڤگێ١٢٣', + '::1', + '2001:db8:0000:1:1:1:1:1', + '::ffff:127.0.0.1', + 'fe80::1234%1', + 'ff08::9abc%10', + 'ff08::9abc%interface10', + 'ff02::5678%pvc1.3', ], invalid: [ - 'äca ', - 'abcß', - 'föö!!', + '127.0.0.1', + '0.0.0.0', + '255.255.255.255', + '1.2.3.4', + '::ffff:287.0.0.1', + '%', + 'fe80::1234%', + 'fe80::1234%1%3%4', + 'fe80%fe80%', ], }); - }); - - it('should validate defined arabic aliases', () => { test({ - validator: 'isAlphanumeric', - args: ['ar-SY'], - valid: [ - 'أبت123', - 'أبتَُِ١٢٣', - ], + validator: 'isIP', + args: [10], + valid: [], invalid: [ - 'abc ', - 'foo!!', - 'ÄBC', - 'FÜübar', - 'Jön', + '127.0.0.1', + '0.0.0.0', + '255.255.255.255', + '1.2.3.4', + '::1', + '2001:db8:0000:1:1:1:1:1', ], }); }); - it('should validate norwegian alphanumeric strings', () => { + it('should validate isIPRange', () => { test({ - validator: 'isAlphanumeric', - args: ['nb-NO'], + validator: 'isIPRange', valid: [ - 'ÆØÅ123', - 'Ære321', - '321Øre', - '123Åre', + '127.0.0.1/24', + '0.0.0.0/0', + '255.255.255.0/32', + '::/0', + '::/128', + '2001::/128', + '2001:800::/128', + '::ffff:127.0.0.1/128', ], invalid: [ - 'äbc123', - 'ÄBC11', - '', + 'abc', + '127.200.230.1/35', + '127.200.230.1/-1', + '1.1.1.1/011', + '1.1.1/24.1', + '1.1.1.1/01', + '1.1.1.1/1.1', + '1.1.1.1/1.', + '1.1.1.1/1/1', + '1.1.1.1', + '::1', + '::1/164', + '2001::/240', + '2001::/-1', + '2001::/001', + '2001::/24.1', + '2001:db8:0000:1:1:1:1:1', + '::ffff:127.0.0.1', ], }); - }); - - it('should validate polish alphanumeric strings', () => { test({ - validator: 'isAlphanumeric', - args: ['pl-PL'], + validator: 'isIPRange', + args: [4], valid: [ - 'kre123ską', - 'zam21knięte', - 'zw23ykłe', - '123', - 'prz23yjęły', - 'świ23ęty', - 'Poz1322wól', + '127.0.0.1/1', + '0.0.0.0/1', + '255.255.255.255/1', + '1.2.3.4/1', + '255.0.0.1/1', + '0.0.1.1/1', ], invalid: [ - '12řiď ', - 'blé!!', - 'föö!2!', + 'abc', + '::1', + '2001:db8:0000:1:1:1:1:1', + '::ffff:127.0.0.1', + '137.132.10.01', + '0.256.0.256', + '255.256.255.256', ], }); - }); - - it('should validate serbian cyrillic alphanumeric strings', () => { test({ - validator: 'isAlphanumeric', - args: ['sr-RS'], + validator: 'isIPRange', + args: [6], valid: [ - 'ШћжЂљЕ123', - 'ЧПСТ132ЋЏ', + '::1/1', + '2001:db8:0000:1:1:1:1:1/1', + '::ffff:127.0.0.1/1', ], invalid: [ - 'řiď ', - 'blé!!', - 'föö!!', + 'abc', + '127.0.0.1', + '0.0.0.0', + '255.255.255.255', + '1.2.3.4', + '::ffff:287.0.0.1', + '::ffff:287.0.0.1/254', + '%', + 'fe80::1234%', + 'fe80::1234%1%3%4', + 'fe80%fe80%', ], }); - }); - - it('should validate serbian latin alphanumeric strings', () => { test({ - validator: 'isAlphanumeric', - args: ['sr-RS@latin'], - valid: [ - 'ŠAabčšđćž123', - 'ŠATRO11Ćčđš', - ], + validator: 'isIPRange', + args: [10], + valid: [], invalid: [ - 'řiď ', - 'blé!!', - 'föö!!', + 'abc', + '127.0.0.1/1', + '0.0.0.0/1', + '255.255.255.255/1', + '1.2.3.4/1', + '::1/1', + '2001:db8:0000:1:1:1:1:1/1', ], }); }); - it('should validate swedish alphanumeric strings', () => { + it('should validate FQDN', () => { test({ - validator: 'isAlphanumeric', - args: ['sv-SE'], + validator: 'isFQDN', valid: [ - 'religiös13', - 'st23jäla', - 'västgöte123', - '123Åre', + 'domain.com', + 'dom.plato', + 'a.domain.co', + 'foo--bar.com', + 'xn--froschgrn-x9a.com', + 'rebecca.blackfriday', + '1337.com', ], invalid: [ - 'AİıÖöÇ窺ĞğÜüZ', - 'foo!!', - '', + 'abc', + '256.0.0.0', + '_.com', + '*.some.com', + 's!ome.com', + 'domain.com/', + '/more.com', + 'domain.com�', + 'domain.co\u00A0m', + 'domain.co\u1680m', + 'domain.co\u2006m', + 'domain.co\u2028m', + 'domain.co\u2029m', + 'domain.co\u202Fm', + 'domain.co\u205Fm', + 'domain.co\u3000m', + 'domain.com\uDC00', + 'domain.co\uEFFFm', + 'domain.co\uFDDAm', + 'domain.co\uFFF4m', + 'domain.com©', + 'example.0', + '192.168.0.9999', + '192.168.0', ], }); }); - - it('should validate turkish alphanumeric strings', () => { + it('should validate FQDN with trailing dot option', () => { test({ - validator: 'isAlphanumeric', - args: ['tr-TR'], - valid: [ - 'AİıÖöÇ窺ĞğÜüZ123', - ], - invalid: [ - 'AİıÖöÇ窺ĞğÜüZ ', - 'foo!!', - 'ÄBC', + validator: 'isFQDN', + args: [ + { allow_trailing_dot: true }, ], - }); - }); - - it('should validate urkrainian alphanumeric strings', () => { - test({ - validator: 'isAlphanumeric', - args: ['uk-UA'], valid: [ - 'АБВГҐДЕЄЖЗИIЇЙКЛМНОПРСТУФХЦШЩЬЮЯ123', - ], - invalid: [ - 'éeoc ', - 'foo!!', - 'ÄBC', - 'ЫыЪъЭэ', + 'example.com.', ], }); }); - - it('should validate greek alphanumeric strings', () => { + it('should invalidate FQDN when not require_tld', () => { test({ - validator: 'isAlphanumeric', - args: ['el-GR'], - valid: [ - 'αβγδεζηθικλμνξοπρςστυφχψω', - 'ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ', - '20θ', - '1234568960', + validator: 'isFQDN', + args: [ + { require_tld: false }, ], invalid: [ - '0AİıÖöÇ窺ĞğÜüZ1', - ' AİıÖöÇ窺ĞğÜüZ ', - 'ÄBC', - 'Heiß', - 'ЫыЪъЭэ', - 'jαckγ', + 'example.0', + '192.168.0', + '192.168.0.9999', ], }); }); - - it('should validate Hebrew alphanumeric strings', () => { + it('should validate FQDN when not require_tld but allow_numeric_tld', () => { test({ - validator: 'isAlphanumeric', - args: ['he'], - valid: [ - 'אבג123', - 'שלום11', - ], - invalid: [ - 'אבג ', - 'לא!!', - 'abc', - ' foo ', + validator: 'isFQDN', + args: [ + { allow_numeric_tld: true, require_tld: false }, ], - }); - }); - - it('should validate Thai alphanumeric strings', () => { - test({ - validator: 'isAlphanumeric', - args: ['th-TH'], valid: [ - 'สวัสดี ๑๒๓', - 'ยินดีต้อนรับทั้ง ๒ คน', - ], - invalid: [ - '1.สวัสดี', - 'ยินดีต้อนรับทั้ง 2 คน', + 'example.0', + '192.168.0', + '192.168.0.9999', ], }); }); - - it('should validate Korea alphanumeric strings', () => { + it('should validate FQDN with wildcard option', () => { test({ - validator: 'isAlphanumeric', - args: ['ko-KR'], - valid: [ - '2002', - '훈민정음', - '1446년훈민정음반포', - ], - invalid: [ - '2022!', - '2019 코로나시작', - '1.로렘입숨', + validator: 'isFQDN', + args: [ + { allow_wildcard: true }, ], - }); - }); - - it('should validate Sinhala alphanumeric strings', () => { - test({ - validator: 'isAlphanumeric', - args: ['si-LK'], valid: [ - 'චතුර', - 'කචට12', - 'ඎඏදාෛපසුගො2', - '1234', - ], - invalid: [ - 'ஆஐअतක', - 'කචට 12', - ' ඎ ', - 'a1234', - 'abc', - '', + '*.example.com', + '*.shop.example.com', ], }); }); - - it('should error on invalid locale', () => { + it('should validate FQDN with required allow_trailing_dot, allow_underscores and allow_numeric_tld options', () => { test({ - validator: 'isAlphanumeric', - args: ['is-NOT'], - error: [ - '1234568960', - 'abc123', + validator: 'isFQDN', + args: [ + { allow_trailing_dot: true, allow_underscores: true, allow_numeric_tld: true }, + ], + valid: [ + 'abc.efg.g1h.', + 'as1s.sad3s.ssa2d.', ], }); }); @@ -5043,31 +3602,6 @@ describe('Validators', () => { }); }); - it('should validate dates against a start date', () => { - test({ - validator: 'isAfter', - args: ['2011-08-03'], - valid: ['2011-08-04', new Date(2011, 8, 10).toString()], - invalid: ['2010-07-02', '2011-08-03', new Date(0).toString(), 'foo'], - }); - test({ - validator: 'isAfter', - valid: ['2100-08-04', new Date(Date.now() + 86400000).toString()], - invalid: ['2010-07-02', new Date(0).toString()], - }); - test({ - validator: 'isAfter', - args: ['2011-08-03'], - valid: ['2015-09-17'], - invalid: ['invalid date'], - }); - test({ - validator: 'isAfter', - args: ['invalid date'], - invalid: ['invalid date', '2015-09-17'], - }); - }); - it('should validate dates against an end date', () => { test({ validator: 'isBefore', diff --git a/test/validators/isAfter.test.js b/test/validators/isAfter.test.js new file mode 100644 index 000000000..e3b49c9da --- /dev/null +++ b/test/validators/isAfter.test.js @@ -0,0 +1,61 @@ +import { test } from '../testFunctions'; + +describe('isAfter', () => { + it('should validate dates against a start date', () => { + test({ + validator: 'isAfter', + args: [{ date: '2011-08-03' }], + valid: ['2011-08-04', new Date(2011, 8, 10).toString()], + invalid: ['2010-07-02', '2011-08-03', new Date(0).toString(), 'foo'], + }); + + test({ + validator: 'isAfter', + valid: ['2100-08-04', new Date(Date.now() + 86400000).toString()], + invalid: ['2010-07-02', new Date(0).toString()], + }); + + test({ + validator: 'isAfter', + args: [{ date: '2011-08-03' }], + valid: ['2015-09-17'], + invalid: ['invalid date'], + }); + + test({ + validator: 'isAfter', + args: [{ date: 'invalid date' }], + invalid: ['invalid date', '2015-09-17'], + }); + }); + + describe('(legacy syntax)', () => { + it('should validate dates against a start date', () => { + test({ + validator: 'isAfter', + args: ['2011-08-03'], + valid: ['2011-08-04', new Date(2011, 8, 10).toString()], + invalid: ['2010-07-02', '2011-08-03', new Date(0).toString(), 'foo'], + }); + + test({ + validator: 'isAfter', + valid: ['2100-08-04', new Date(Date.now() + 86400000).toString()], + invalid: ['2010-07-02', new Date(0).toString()], + }); + + test({ + validator: 'isAfter', + args: ['2011-08-03'], + valid: ['2015-09-17'], + invalid: ['invalid date'], + }); + + test({ + validator: 'isAfter', + args: ['invalid date'], + invalid: ['invalid date', '2015-09-17'], + }); + }); + }); +}); diff --git a/test/validators/isAlpha.test.js b/test/validators/isAlpha.test.js new file mode 100644 index 000000000..ee8d4a4d3 --- /dev/null +++ b/test/validators/isAlpha.test.js @@ -0,0 +1,1472 @@ +import { test } from '../testFunctions'; + +describe('isAlpha', () => { + it('should validate alpha strings with missing `locale` option', () => { + test({ + validator: 'isAlpha', + valid: [ + 'abc', + 'ABC', + 'FoObar', + ], + invalid: [ + 'abc1', + ' foo ', + '', + 'ÄBC', + 'FÜübar', + 'Jön', + 'Heiß', + ], + }); + + test({ + validator: 'isAlpha', + args: [{ ignore: '- /' }], // ignore [space-/] + valid: [ + 'en-US', + 'this is a valid alpha string', + 'us/usa', + ], + invalid: [ + '1. this is not a valid alpha string', + 'this$is also not a valid.alpha string', + 'this is also not a valid alpha string.', + ], + }); + }); + + it('should validate alpha strings with ignored characters', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'en-US', ignore: '- /' }], // ignore [space-/] + valid: [ + 'en-US', + 'this is a valid alpha string', + 'us/usa', + ], + invalid: [ + '1. this is not a valid alpha string', + 'this$is also not a valid.alpha string', + 'this is also not a valid alpha string.', + ], + }); + + test({ + validator: 'isAlpha', + args: [{ locale: 'en-US', ignore: /[\s/-]/g }], // ignore [space -] + valid: [ + 'en-US', + 'this is a valid alpha string', + ], + invalid: [ + '1. this is not a valid alpha string', + 'this$is also not a valid.alpha string', + 'this is also not a valid alpha string.', + ], + }); + + test({ + validator: 'isAlpha', + args: [{ locale: 'en-US', ignore: 1234 }], // invalid ignore matcher + error: [ + 'alpha', + ], + }); + }); + + it('should validate Azerbaijani alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: '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', + args: [{ locale: 'bg-BG' }], + valid: [ + 'абв', + 'АБВ', + 'жаба', + 'яГоДа', + ], + invalid: [ + 'abc1', + ' foo ', + '', + 'ЁЧПС', + '_аз_обичам_обувки_', + 'ехо!', + ], + }); + }); + + it('should validate Bengali alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'bn-BD' }], + valid: [ + 'অয়াওর', + 'ফগফদ্রত', + 'ফদ্ম্যতভ', + 'বেরেওভচনভন', + 'আমারবাসগা', + ], + invalid: [ + 'দাস২৩৪', + ' দ্গফহ্নভ ', + '', + '(গফদ)', + ], + }); + }); + + it('should validate czech alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'cs-CZ' }], + valid: [ + 'žluťoučký', + 'KŮŇ', + 'Pěl', + 'Ďábelské', + 'ódy', + ], + invalid: [ + 'ábc1', + ' fůj ', + '', + ], + }); + }); + + it('should validate slovak alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'sk-SK' }], + valid: [ + 'môj', + 'ľúbím', + 'mäkčeň', + 'stĹp', + 'vŕba', + 'ňorimberk', + 'ťava', + 'žanéta', + 'Ďábelské', + 'ódy', + ], + invalid: [ + '1moj', + '你好世界', + ' Привет мир ', + 'مرحبا العا ', + ], + }); + }); + + it('should validate danish alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'da-DK' }], + valid: [ + 'aøå', + 'Ære', + 'Øre', + 'Åre', + ], + invalid: [ + 'äbc123', + 'ÄBC11', + '', + ], + }); + }); + + it('should validate dutch alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'nl-NL' }], + valid: [ + 'Kán', + 'één', + 'vóór', + 'nú', + 'héél', + ], + invalid: [ + 'äca ', + 'abcß', + 'Øre', + ], + }); + }); + + it('should validate german alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'de-DE' }], + valid: [ + 'äbc', + 'ÄBC', + 'FöÖbär', + 'Heiß', + ], + invalid: [ + 'äbc1', + ' föö ', + '', + ], + }); + }); + + it('should validate hungarian alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'hu-HU' }], + valid: [ + 'árvíztűrőtükörfúrógép', + 'ÁRVÍZTŰRŐTÜKÖRFÚRÓGÉP', + ], + invalid: [ + 'äbc1', + ' fäö ', + 'Heiß', + '', + ], + }); + }); + + it('should validate portuguese alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'pt-PT' }], + valid: [ + 'palíndromo', + 'órgão', + 'qwértyúão', + 'àäãcëüïÄÏÜ', + ], + invalid: [ + '12abc', + 'Heiß', + 'Øre', + 'æøå', + '', + ], + }); + }); + + it('should validate italian alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'it-IT' }], + valid: [ + 'àéèìîóòù', + 'correnti', + 'DEFINIZIONE', + 'compilazione', + 'metró', + 'pèsca', + 'PÉSCA', + 'genî', + ], + invalid: [ + 'äbc123', + 'ÄBC11', + 'æøå', + '', + ], + }); + }); + + it('should validate Japanese alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'ja-JP' }], + valid: [ + 'あいうえお', + 'がぎぐげご', + 'ぁぃぅぇぉ', + 'アイウエオ', + 'ァィゥェ', + 'アイウエオ', + '吾輩は猫である', + '臥薪嘗胆', + '新世紀エヴァンゲリオン', + '天国と地獄', + '七人の侍', + 'シン・ウルトラマン', + ], + invalid: [ + 'あいう123', + 'abcあいう', + '1984', + ], + }); + }); + + it('should validate Vietnamese alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'vi-VN' }], + valid: [ + 'thiến', + 'nghiêng', + 'xin', + 'chào', + 'thế', + 'giới', + ], + invalid: [ + 'thầy3', + 'Ba gà', + '', + ], + }); + }); + + it('should validate arabic alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'ar' }], + valid: [ + 'أبت', + 'اَبِتَثّجً', + ], + invalid: [ + '١٢٣أبت', + '١٢٣', + 'abc1', + ' foo ', + '', + 'ÄBC', + 'FÜübar', + 'Jön', + 'Heiß', + ], + }); + }); + + it('should validate farsi alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'fa-IR' }], + valid: [ + 'پدر', + 'مادر', + 'برادر', + 'خواهر', + ], + invalid: [ + 'فارسی۱۲۳', + '۱۶۴', + 'abc1', + ' foo ', + '', + 'ÄBC', + 'FÜübar', + 'Jön', + 'Heiß', + ], + }); + }); + + it('should validate finnish alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'fi-FI' }], + valid: [ + 'äiti', + 'Öljy', + 'Åke', + 'testÖ', + ], + invalid: [ + 'AİıÖöÇ窺ĞğÜüZ', + 'äöå123', + '', + ], + }); + }); + + it('should validate kurdish alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'ku-IQ' }], + valid: [ + 'ئؤڤگێ', + 'کوردستان', + ], + invalid: [ + 'ئؤڤگێ١٢٣', + '١٢٣', + 'abc1', + ' foo ', + '', + 'ÄBC', + 'FÜübar', + 'Jön', + 'Heiß', + ], + }); + }); + + it('should validate norwegian alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'nb-NO' }], + valid: [ + 'aøå', + 'Ære', + 'Øre', + 'Åre', + ], + invalid: [ + 'äbc123', + 'ÄBC11', + '', + ], + }); + }); + + it('should validate polish alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'pl-PL' }], + valid: [ + 'kreską', + 'zamknięte', + 'zwykłe', + 'kropką', + 'przyjęły', + 'święty', + 'Pozwól', + ], + invalid: [ + '12řiď ', + 'blé!!', + 'föö!2!', + ], + }); + }); + + it('should validate serbian cyrillic alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'sr-RS' }], + valid: [ + 'ШћжЂљЕ', + 'ЧПСТЋЏ', + ], + invalid: [ + 'řiď ', + 'blé33!!', + 'föö!!', + ], + }); + }); + + it('should validate serbian latin alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'sr-RS@latin' }], + valid: [ + 'ŠAabčšđćž', + 'ŠATROĆčđš', + ], + invalid: [ + '12řiď ', + 'blé!!', + 'föö!2!', + ], + }); + }); + + it('should validate spanish alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'es-ES' }], + valid: [ + 'ábcó', + 'ÁBCÓ', + 'dormís', + 'volvés', + 'español', + ], + invalid: [ + 'äca ', + 'abcß', + 'föö!!', + ], + }); + }); + + it('should validate swedish alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'sv-SE' }], + valid: [ + 'religiös', + 'stjäla', + 'västgöte', + 'Åre', + ], + invalid: [ + 'AİıÖöÇ窺ĞğÜüZ', + 'religiös23', + '', + ], + }); + }); + + it('should validate defined arabic locales alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'ar-SY' }], + valid: [ + 'أبت', + 'اَبِتَثّجً', + ], + invalid: [ + '١٢٣أبت', + '١٢٣', + 'abc1', + ' foo ', + '', + 'ÄBC', + 'FÜübar', + 'Jön', + 'Heiß', + ], + }); + }); + + it('should validate turkish alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'tr-TR' }], + valid: [ + 'AİıÖöÇ窺ĞğÜüZ', + ], + invalid: [ + '0AİıÖöÇ窺ĞğÜüZ1', + ' AİıÖöÇ窺ĞğÜüZ ', + 'abc1', + ' foo ', + '', + 'ÄBC', + 'Heiß', + ], + }); + }); + + it('should validate urkrainian alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'uk-UA' }], + valid: [ + 'АБВГҐДЕЄЖЗИIЇЙКЛМНОПРСТУФХЦШЩЬЮЯ', + ], + invalid: [ + '0AİıÖöÇ窺ĞğÜüZ1', + ' AİıÖöÇ窺ĞğÜüZ ', + 'abc1', + ' foo ', + '', + 'ÄBC', + 'Heiß', + 'ЫыЪъЭэ', + ], + }); + }); + + it('should validate greek alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'el-GR' }], + valid: [ + 'αβγδεζηθικλμνξοπρςστυφχψω', + 'ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ', + 'άέήίΰϊϋόύώ', + 'ΆΈΉΊΪΫΎΏ', + ], + invalid: [ + '0AİıÖöÇ窺ĞğÜüZ1', + ' AİıÖöÇ窺ĞğÜüZ ', + 'ÄBC', + 'Heiß', + 'ЫыЪъЭэ', + '120', + 'jαckγ', + ], + }); + }); + + it('should validate Hebrew alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'he' }], + valid: [ + 'בדיקה', + 'שלום', + ], + invalid: [ + 'בדיקה123', + ' foo ', + 'abc1', + '', + ], + }); + }); + + it('should validate Hindi alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'hi-IN' }], + valid: [ + 'अतअपनाअपनीअपनेअभीअंदरआदिआपइत्यादिइनइनकाइन्हींइन्हेंइन्होंइसइसकाइसकीइसकेइसमेंइसीइसेउनउनकाउनकीउनकेउनकोउन्हींउन्हेंउन्होंउसउसकेउसीउसेएकएवंएसऐसेऔरकईकरकरताकरतेकरनाकरनेकरेंकहतेकहाकाकाफ़ीकिकितनाकिन्हेंकिन्होंकियाकिरकिसकिसीकिसेकीकुछकुलकेकोकोईकौनकौनसागयाघरजबजहाँजाजितनाजिनजिन्हेंजिन्होंजिसजिसेजीधरजैसाजैसेजोतकतबतरहतिनतिन्हेंतिन्होंतिसतिसेतोथाथीथेदबारादियादुसरादूसरेदोद्वाराननकेनहींनानिहायतनीचेनेपरपहलेपूरापेफिरबनीबहीबहुतबादबालाबिलकुलभीभीतरमगरमानोमेमेंयदियहयहाँयहीयायिहयेरखेंरहारहेऱ्वासालिएलियेलेकिनववग़ैरहवर्गवहवहाँवहींवालेवुहवेवोसकतासकतेसबसेसभीसाथसाबुतसाभसारासेसोसंगहीहुआहुईहुएहैहैंहोहोताहोतीहोतेहोनाहोने', + 'इन्हें', + ], + invalid: [ + 'अत०२३४५६७८९', + 'अत 12', + ' अत ', + 'abc1', + 'abc', + '', + ], + }); + }); + + it('should validate persian alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'fa-IR' }], + valid: [ + 'تست', + 'عزیزم', + 'ح', + ], + invalid: [ + 'تست 1', + ' عزیزم ', + '', + ], + }); + }); + + it('should validate Thai alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'th-TH' }], + valid: [ + 'สวัสดี', + 'ยินดีต้อนรับ เทสเคส', + ], + invalid: [ + 'สวัสดีHi', + '123 ยินดีต้อนรับ', + 'ยินดีต้อนรับ-๑๒๓', + ], + }); + }); + + it('should validate Korea alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'ko-KR' }], + valid: [ + 'ㄱ', + 'ㅑ', + 'ㄱㄴㄷㅏㅕ', + '세종대왕', + '나랏말싸미듕귁에달아문자와로서르사맛디아니할쎄', + ], + invalid: [ + 'abc', + '123', + '흥선대원군 문호개방', + '1592년임진왜란', + '대한민국!', + ], + }); + }); + + it('should validate Sinhala alpha strings', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'si-LK' }], + valid: [ + 'චතුර', + 'කචටදබ', + 'ඎඏදාෛපසුගො', + ], + invalid: [ + 'ஆஐअतක', + 'කචට 12', + ' ඎ ', + 'abc1', + 'abc', + '', + ], + }); + }); + + it('should error on invalid locale', () => { + test({ + validator: 'isAlpha', + args: [{ locale: 'is-NOT' }], + error: [ + 'abc', + 'ABC', + ], + }); + }); + + describe('legacy', () => { + it('should validate alpha strings', () => { + test({ + validator: 'isAlpha', + valid: [ + 'abc', + 'ABC', + 'FoObar', + ], + invalid: [ + 'abc1', + ' foo ', + '', + 'ÄBC', + 'FÜübar', + 'Jön', + 'Heiß', + ], + }); + }); + + it('should validate alpha string with ignored characters', () => { + test({ + validator: 'isAlpha', + args: ['en-US', { ignore: '- /' }], // ignore [space-/] + valid: [ + 'en-US', + 'this is a valid alpha string', + 'us/usa', + ], + invalid: [ + '1. this is not a valid alpha string', + 'this$is also not a valid.alpha string', + 'this is also not a valid alpha string.', + ], + }); + + test({ + validator: 'isAlpha', + args: ['en-US', { ignore: /[\s/-]/g }], // ignore [space -] + valid: [ + 'en-US', + 'this is a valid alpha string', + ], + invalid: [ + '1. this is not a valid alpha string', + 'this$is also not a valid.alpha string', + 'this is also not a valid alpha string.', + ], + }); + + test({ + validator: 'isAlpha', + args: ['en-US', { ignore: 1234 }], // invalid ignore matcher + error: [ + 'alpha', + ], + }); + }); + + 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', + args: ['bg-BG'], + valid: [ + 'абв', + 'АБВ', + 'жаба', + 'яГоДа', + ], + invalid: [ + 'abc1', + ' foo ', + '', + 'ЁЧПС', + '_аз_обичам_обувки_', + 'ехо!', + ], + }); + }); + + it('should validate Bengali alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['bn-BD'], + valid: [ + 'অয়াওর', + 'ফগফদ্রত', + 'ফদ্ম্যতভ', + 'বেরেওভচনভন', + 'আমারবাসগা', + ], + invalid: [ + 'দাস২৩৪', + ' দ্গফহ্নভ ', + '', + '(গফদ)', + ], + }); + }); + + it('should validate czech alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['cs-CZ'], + valid: [ + 'žluťoučký', + 'KŮŇ', + 'Pěl', + 'Ďábelské', + 'ódy', + ], + invalid: [ + 'ábc1', + ' fůj ', + '', + ], + }); + }); + + it('should validate slovak alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['sk-SK'], + valid: [ + 'môj', + 'ľúbím', + 'mäkčeň', + 'stĹp', + 'vŕba', + 'ňorimberk', + 'ťava', + 'žanéta', + 'Ďábelské', + 'ódy', + ], + invalid: [ + '1moj', + '你好世界', + ' Привет мир ', + 'مرحبا العا ', + ], + }); + }); + + it('should validate danish alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['da-DK'], + valid: [ + 'aøå', + 'Ære', + 'Øre', + 'Åre', + ], + invalid: [ + 'äbc123', + 'ÄBC11', + '', + ], + }); + }); + + it('should validate dutch alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['nl-NL'], + valid: [ + 'Kán', + 'één', + 'vóór', + 'nú', + 'héél', + ], + invalid: [ + 'äca ', + 'abcß', + 'Øre', + ], + }); + }); + + it('should validate german alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['de-DE'], + valid: [ + 'äbc', + 'ÄBC', + 'FöÖbär', + 'Heiß', + ], + invalid: [ + 'äbc1', + ' föö ', + '', + ], + }); + }); + + it('should validate hungarian alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['hu-HU'], + valid: [ + 'árvíztűrőtükörfúrógép', + 'ÁRVÍZTŰRŐTÜKÖRFÚRÓGÉP', + ], + invalid: [ + 'äbc1', + ' fäö ', + 'Heiß', + '', + ], + }); + }); + + it('should validate portuguese alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['pt-PT'], + valid: [ + 'palíndromo', + 'órgão', + 'qwértyúão', + 'àäãcëüïÄÏÜ', + ], + invalid: [ + '12abc', + 'Heiß', + 'Øre', + 'æøå', + '', + ], + }); + }); + + it('should validate italian alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['it-IT'], + valid: [ + 'àéèìîóòù', + 'correnti', + 'DEFINIZIONE', + 'compilazione', + 'metró', + 'pèsca', + 'PÉSCA', + 'genî', + ], + invalid: [ + 'äbc123', + 'ÄBC11', + 'æøå', + '', + ], + }); + }); + + it('should validate Japanese alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['ja-JP'], + valid: [ + 'あいうえお', + 'がぎぐげご', + 'ぁぃぅぇぉ', + 'アイウエオ', + 'ァィゥェ', + 'アイウエオ', + '吾輩は猫である', + '臥薪嘗胆', + '新世紀エヴァンゲリオン', + '天国と地獄', + '七人の侍', + 'シン・ウルトラマン', + ], + invalid: [ + 'あいう123', + 'abcあいう', + '1984', + ], + }); + }); + + it('should validate Vietnamese alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['vi-VN'], + valid: [ + 'thiến', + 'nghiêng', + 'xin', + 'chào', + 'thế', + 'giới', + ], + invalid: [ + 'thầy3', + 'Ba gà', + '', + ], + }); + }); + + it('should validate arabic alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['ar'], + valid: [ + 'أبت', + 'اَبِتَثّجً', + ], + invalid: [ + '١٢٣أبت', + '١٢٣', + 'abc1', + ' foo ', + '', + 'ÄBC', + 'FÜübar', + 'Jön', + 'Heiß', + ], + }); + }); + + it('should validate farsi alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['fa-IR'], + valid: [ + 'پدر', + 'مادر', + 'برادر', + 'خواهر', + ], + invalid: [ + 'فارسی۱۲۳', + '۱۶۴', + 'abc1', + ' foo ', + '', + 'ÄBC', + 'FÜübar', + 'Jön', + 'Heiß', + ], + }); + }); + + it('should validate finnish alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['fi-FI'], + valid: [ + 'äiti', + 'Öljy', + 'Åke', + 'testÖ', + ], + invalid: [ + 'AİıÖöÇ窺ĞğÜüZ', + 'äöå123', + '', + ], + }); + }); + + it('should validate kurdish alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['ku-IQ'], + valid: [ + 'ئؤڤگێ', + 'کوردستان', + ], + invalid: [ + 'ئؤڤگێ١٢٣', + '١٢٣', + 'abc1', + ' foo ', + '', + 'ÄBC', + 'FÜübar', + 'Jön', + 'Heiß', + ], + }); + }); + + it('should validate norwegian alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['nb-NO'], + valid: [ + 'aøå', + 'Ære', + 'Øre', + 'Åre', + ], + invalid: [ + 'äbc123', + 'ÄBC11', + '', + ], + }); + }); + + it('should validate polish alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['pl-PL'], + valid: [ + 'kreską', + 'zamknięte', + 'zwykłe', + 'kropką', + 'przyjęły', + 'święty', + 'Pozwól', + ], + invalid: [ + '12řiď ', + 'blé!!', + 'föö!2!', + ], + }); + }); + + it('should validate serbian cyrillic alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['sr-RS'], + valid: [ + 'ШћжЂљЕ', + 'ЧПСТЋЏ', + ], + invalid: [ + 'řiď ', + 'blé33!!', + 'föö!!', + ], + }); + }); + + it('should validate serbian latin alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['sr-RS@latin'], + valid: [ + 'ŠAabčšđćž', + 'ŠATROĆčđš', + ], + invalid: [ + '12řiď ', + 'blé!!', + 'föö!2!', + ], + }); + }); + + it('should validate spanish alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['es-ES'], + valid: [ + 'ábcó', + 'ÁBCÓ', + 'dormís', + 'volvés', + 'español', + ], + invalid: [ + 'äca ', + 'abcß', + 'föö!!', + ], + }); + }); + + it('should validate swedish alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['sv-SE'], + valid: [ + 'religiös', + 'stjäla', + 'västgöte', + 'Åre', + ], + invalid: [ + 'AİıÖöÇ窺ĞğÜüZ', + 'religiös23', + '', + ], + }); + }); + + it('should validate defined arabic locales alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['ar-SY'], + valid: [ + 'أبت', + 'اَبِتَثّجً', + ], + invalid: [ + '١٢٣أبت', + '١٢٣', + 'abc1', + ' foo ', + '', + 'ÄBC', + 'FÜübar', + 'Jön', + 'Heiß', + ], + }); + }); + + it('should validate turkish alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['tr-TR'], + valid: [ + 'AİıÖöÇ窺ĞğÜüZ', + ], + invalid: [ + '0AİıÖöÇ窺ĞğÜüZ1', + ' AİıÖöÇ窺ĞğÜüZ ', + 'abc1', + ' foo ', + '', + 'ÄBC', + 'Heiß', + ], + }); + }); + + it('should validate urkrainian alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['uk-UA'], + valid: [ + 'АБВГҐДЕЄЖЗИIЇЙКЛМНОПРСТУФХЦШЩЬЮЯ', + ], + invalid: [ + '0AİıÖöÇ窺ĞğÜüZ1', + ' AİıÖöÇ窺ĞğÜüZ ', + 'abc1', + ' foo ', + '', + 'ÄBC', + 'Heiß', + 'ЫыЪъЭэ', + ], + }); + }); + + it('should validate greek alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['el-GR'], + valid: [ + 'αβγδεζηθικλμνξοπρςστυφχψω', + 'ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ', + 'άέήίΰϊϋόύώ', + 'ΆΈΉΊΪΫΎΏ', + ], + invalid: [ + '0AİıÖöÇ窺ĞğÜüZ1', + ' AİıÖöÇ窺ĞğÜüZ ', + 'ÄBC', + 'Heiß', + 'ЫыЪъЭэ', + '120', + 'jαckγ', + ], + }); + }); + + it('should validate Hebrew alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['he'], + valid: [ + 'בדיקה', + 'שלום', + ], + invalid: [ + 'בדיקה123', + ' foo ', + 'abc1', + '', + ], + }); + }); + + it('should validate Hindi alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['hi-IN'], + valid: [ + 'अतअपनाअपनीअपनेअभीअंदरआदिआपइत्यादिइनइनकाइन्हींइन्हेंइन्होंइसइसकाइसकीइसकेइसमेंइसीइसेउनउनकाउनकीउनकेउनकोउन्हींउन्हेंउन्होंउसउसकेउसीउसेएकएवंएसऐसेऔरकईकरकरताकरतेकरनाकरनेकरेंकहतेकहाकाकाफ़ीकिकितनाकिन्हेंकिन्होंकियाकिरकिसकिसीकिसेकीकुछकुलकेकोकोईकौनकौनसागयाघरजबजहाँजाजितनाजिनजिन्हेंजिन्होंजिसजिसेजीधरजैसाजैसेजोतकतबतरहतिनतिन्हेंतिन्होंतिसतिसेतोथाथीथेदबारादियादुसरादूसरेदोद्वाराननकेनहींनानिहायतनीचेनेपरपहलेपूरापेफिरबनीबहीबहुतबादबालाबिलकुलभीभीतरमगरमानोमेमेंयदियहयहाँयहीयायिहयेरखेंरहारहेऱ्वासालिएलियेलेकिनववग़ैरहवर्गवहवहाँवहींवालेवुहवेवोसकतासकतेसबसेसभीसाथसाबुतसाभसारासेसोसंगहीहुआहुईहुएहैहैंहोहोताहोतीहोतेहोनाहोने', + 'इन्हें', + ], + invalid: [ + 'अत०२३४५६७८९', + 'अत 12', + ' अत ', + 'abc1', + 'abc', + '', + ], + }); + }); + + it('should validate persian alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['fa-IR'], + valid: [ + 'تست', + 'عزیزم', + 'ح', + ], + invalid: [ + 'تست 1', + ' عزیزم ', + '', + ], + }); + }); + + it('should validate Thai alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['th-TH'], + valid: [ + 'สวัสดี', + 'ยินดีต้อนรับ เทสเคส', + ], + invalid: [ + 'สวัสดีHi', + '123 ยินดีต้อนรับ', + 'ยินดีต้อนรับ-๑๒๓', + ], + }); + }); + + it('should validate Korea alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['ko-KR'], + valid: [ + 'ㄱ', + 'ㅑ', + 'ㄱㄴㄷㅏㅕ', + '세종대왕', + '나랏말싸미듕귁에달아문자와로서르사맛디아니할쎄', + ], + invalid: [ + 'abc', + '123', + '흥선대원군 문호개방', + '1592년임진왜란', + '대한민국!', + ], + }); + }); + + it('should validate Sinhala alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['si-LK'], + valid: [ + 'චතුර', + 'කචටදබ', + 'ඎඏදාෛපසුගො', + ], + invalid: [ + 'ஆஐअतක', + 'කචට 12', + ' ඎ ', + 'abc1', + 'abc', + '', + ], + }); + }); + + it('should error on invalid locale', () => { + test({ + validator: 'isAlpha', + args: ['is-NOT'], + error: [ + 'abc', + 'ABC', + ], + }); + }); + }); +}); diff --git a/test/validators/isAlphanumeric.test.js b/test/validators/isAlphanumeric.test.js new file mode 100644 index 000000000..cd883fb61 --- /dev/null +++ b/test/validators/isAlphanumeric.test.js @@ -0,0 +1,1352 @@ +import { test } from '../testFunctions'; + +describe('isAlphanumeric', () => { + it('should validate alphanumeric strings with missing `locale` option', () => { + test({ + validator: 'isAlphanumeric', + valid: [ + 'abc123', + 'ABC11', + ], + invalid: [ + 'abc ', + 'foo!!', + 'ÄBC', + 'FÜübar', + 'Jön', + ], + }); + + test({ + validator: 'isAlphanumeric', + args: [{ ignore: '@_- ' }], // ignore [@ space _ -] + valid: [ + 'Hello@123', + 'this is a valid alphaNumeric string', + 'En-US @ alpha_numeric', + ], + invalid: [ + 'In*Valid', + 'hello$123', + '{invalid}', + ], + }); + }); + + it('should validate alphanumeric string with ignored characters', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'en-US', ignore: '@_- ' }], // ignore [@ space _ -] + valid: [ + 'Hello@123', + 'this is a valid alphaNumeric string', + 'En-US @ alpha_numeric', + ], + invalid: [ + 'In*Valid', + 'hello$123', + '{invalid}', + ], + }); + + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'en-US', ignore: /[\s/-]/g }], // ignore [space -] + valid: [ + 'en-US', + 'this is a valid alphaNumeric string', + ], + invalid: [ + 'INVALID$ AlphaNum Str', + 'hello@123', + 'abc*123', + ], + }); + + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'en-US', ignore: 1234 }], // invalid ignore matcher (ignore should be instance of a String or RegExp) + error: [ + 'alpha', + ], + }); + }); + + it('should validate defined english aliases', () => { + test({ + validator: 'isAlphanumeric', + args: ['en-GB'], + valid: [ + 'abc123', + 'ABC11', + ], + invalid: [ + 'abc ', + 'foo!!', + 'ÄBC', + 'FÜübar', + 'Jön', + ], + }); + }); + + it('should validate Azerbaijani alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: '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', + args: [{ locale: 'bg-BG' }], + valid: [ + 'абв1', + '4АБ5В6', + 'жаба', + 'яГоДа2', + 'йЮя', + '123', + ], + invalid: [ + ' ', + '789 ', + 'hello000', + ], + }); + }); + + it('should validate Bengali alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'bn-BD' }], + valid: [ + 'দ্গজ্ঞহ্রত্য১২৩', + 'দ্গগফ৮৯০', + 'চব৩৬৫ভবচ', + '১২৩৪', + '৩৪২৩৪দফজ্ঞদফ', + ], + invalid: [ + ' ', + '১২৩ ', + 'hel৩২0', + ], + }); + }); + + it('should validate czech alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'cs-CZ' }], + valid: [ + 'řiť123', + 'KŮŇ11', + ], + invalid: [ + 'řiď ', + 'blé!!', + ], + }); + }); + + it('should validate slovak alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'sk-SK' }], + valid: [ + '1môj', + '2ľúbím', + '3mäkčeň', + '4stĹp', + '5vŕba', + '6ňorimberk', + '7ťava', + '8žanéta', + '9Ďábelské', + '10ódy', + ], + invalid: [ + '1moj!', + '你好世界', + ' Привет мир ', + ], + }); + }); + + it('should validate danish alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'da-DK' }], + valid: [ + 'ÆØÅ123', + 'Ære321', + '321Øre', + '123Åre', + ], + invalid: [ + 'äbc123', + 'ÄBC11', + '', + ], + }); + }); + + it('should validate dutch alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'nl-NL' }], + valid: [ + 'Kán123', + 'één354', + 'v4óór', + 'nú234', + 'hé54él', + ], + invalid: [ + '1äca ', + 'ab3cß', + 'Øre', + ], + }); + }); + + it('should validate finnish alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'fi-FI' }], + valid: [ + 'äiti124', + 'ÖLJY1234', + '123Åke', + '451åå23', + ], + invalid: [ + 'AİıÖöÇ窺ĞğÜüZ', + 'foo!!', + '', + ], + }); + }); + + it('should validate german alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'de-DE' }], + valid: [ + 'äbc123', + 'ÄBC11', + ], + invalid: [ + 'äca ', + 'föö!!', + ], + }); + }); + + it('should validate hungarian alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'hu-HU' }], + valid: [ + '0árvíztűrőtükörfúrógép123', + '0ÁRVÍZTŰRŐTÜKÖRFÚRÓGÉP123', + ], + invalid: [ + '1időúr!', + 'äbc1', + ' fäö ', + 'Heiß!', + '', + ], + }); + }); + + it('should validate portuguese alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'pt-PT' }], + valid: [ + 'palíndromo', + '2órgão', + 'qwértyúão9', + 'àäãcë4üïÄÏÜ', + ], + invalid: [ + '!abc', + 'Heiß', + 'Øre', + 'æøå', + '', + ], + }); + }); + + it('should validate italian alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'it-IT' }], + valid: [ + '123àéèìîóòù', + '123correnti', + 'DEFINIZIONE321', + 'compil123azione', + 'met23ró', + 'pès56ca', + 'PÉS45CA', + 'gen45î', + ], + invalid: [ + 'äbc123', + 'ÄBC11', + 'æøå', + '', + ], + }); + }); + + it('should validate spanish alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'es-ES' }], + valid: [ + 'ábcó123', + 'ÁBCÓ11', + ], + invalid: [ + 'äca ', + 'abcß', + 'föö!!', + ], + }); + }); + + it('should validate Vietnamese alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'vi-VN' }], + valid: [ + 'Thầy3', + '3Gà', + ], + invalid: [ + 'toang!', + 'Cậu Vàng', + ], + }); + }); + + it('should validate arabic alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'ar' }], + valid: [ + 'أبت123', + 'أبتَُِ١٢٣', + ], + invalid: [ + 'äca ', + 'abcß', + 'föö!!', + ], + }); + }); + + it('should validate Hindi alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'hi-IN' }], + valid: [ + 'अतअपनाअपनीअपनेअभीअंदरआदिआपइत्यादिइनइनकाइन्हींइन्हेंइन्होंइसइसकाइसकीइसकेइसमेंइसीइसेउनउनकाउनकीउनकेउनकोउन्हींउन्हेंउन्होंउसउसकेउसीउसेएकएवंएसऐसेऔरकईकरकरताकरतेकरनाकरनेकरेंकहतेकहाकाकाफ़ीकिकितनाकिन्हेंकिन्होंकियाकिरकिसकिसीकिसेकीकुछकुलकेकोकोईकौनकौनसागयाघरजबजहाँजाजितनाजिनजिन्हेंजिन्होंजिसजिसेजीधरजैसाजैसेजोतकतबतरहतिनतिन्हेंतिन्होंतिसतिसेतोथाथीथेदबारादियादुसरादूसरेदोद्वाराननकेनहींनानिहायतनीचेनेपरपहलेपूरापेफिरबनीबहीबहुतबादबालाबिलकुलभीभीतरमगरमानोमेमेंयदियहयहाँयहीयायिहयेरखेंरहारहेऱ्वासालिएलियेलेकिनववग़ैरहवर्गवहवहाँवहींवालेवुहवेवोसकतासकतेसबसेसभीसाथसाबुतसाभसारासेसोसंगहीहुआहुईहुएहैहैंहोहोताहोतीहोतेहोनाहोने०२३४५६७८९', + 'इन्हें४५६७८९', + ], + invalid: [ + 'अत ०२३४५६७८९', + ' ३४५६७८९', + '12 ', + ' अत ', + 'abc1', + 'abc', + '', + ], + }); + }); + + it('should validate farsi alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'fa-IR' }], + valid: [ + 'پارسی۱۲۳', + '۱۴۵۶', + 'مژگان9', + ], + invalid: [ + 'äca ', + 'abcßة', + 'föö!!', + '٤٥٦', + ], + }); + }); + + it('should validate Japanese alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'ja-JP' }], + valid: [ + 'あいうえお123', + '123がぎぐげご', + 'ぁぃぅぇぉ', + 'アイウエオ', + 'ァィゥェ', + 'アイウエオ', + '20世紀少年', + '華氏451度', + ], + invalid: [ + ' あいう123 ', + 'abcあいう', + '生きろ!!', + ], + }); + }); + + it('should validate kurdish alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'ku-IQ' }], + valid: [ + 'ئؤڤگێ١٢٣', + ], + invalid: [ + 'äca ', + 'abcß', + 'föö!!', + ], + }); + }); + + it('should validate defined arabic aliases', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'ar-SY' }], + valid: [ + 'أبت123', + 'أبتَُِ١٢٣', + ], + invalid: [ + 'abc ', + 'foo!!', + 'ÄBC', + 'FÜübar', + 'Jön', + ], + }); + }); + + it('should validate norwegian alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'nb-NO' }], + valid: [ + 'ÆØÅ123', + 'Ære321', + '321Øre', + '123Åre', + ], + invalid: [ + 'äbc123', + 'ÄBC11', + '', + ], + }); + }); + + it('should validate polish alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'pl-PL' }], + valid: [ + 'kre123ską', + 'zam21knięte', + 'zw23ykłe', + '123', + 'prz23yjęły', + 'świ23ęty', + 'Poz1322wól', + ], + invalid: [ + '12řiď ', + 'blé!!', + 'föö!2!', + ], + }); + }); + + it('should validate serbian cyrillic alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'sr-RS' }], + valid: [ + 'ШћжЂљЕ123', + 'ЧПСТ132ЋЏ', + ], + invalid: [ + 'řiď ', + 'blé!!', + 'föö!!', + ], + }); + }); + + it('should validate serbian latin alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'sr-RS@latin' }], + valid: [ + 'ŠAabčšđćž123', + 'ŠATRO11Ćčđš', + ], + invalid: [ + 'řiď ', + 'blé!!', + 'föö!!', + ], + }); + }); + + it('should validate swedish alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'sv-SE' }], + valid: [ + 'religiös13', + 'st23jäla', + 'västgöte123', + '123Åre', + ], + invalid: [ + 'AİıÖöÇ窺ĞğÜüZ', + 'foo!!', + '', + ], + }); + }); + + it('should validate turkish alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'tr-TR' }], + valid: [ + 'AİıÖöÇ窺ĞğÜüZ123', + ], + invalid: [ + 'AİıÖöÇ窺ĞğÜüZ ', + 'foo!!', + 'ÄBC', + ], + }); + }); + + it('should validate urkrainian alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'uk-UA' }], + valid: [ + 'АБВГҐДЕЄЖЗИIЇЙКЛМНОПРСТУФХЦШЩЬЮЯ123', + ], + invalid: [ + 'éeoc ', + 'foo!!', + 'ÄBC', + 'ЫыЪъЭэ', + ], + }); + }); + + it('should validate greek alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'el-GR' }], + valid: [ + 'αβγδεζηθικλμνξοπρςστυφχψω', + 'ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ', + '20θ', + '1234568960', + ], + invalid: [ + '0AİıÖöÇ窺ĞğÜüZ1', + ' AİıÖöÇ窺ĞğÜüZ ', + 'ÄBC', + 'Heiß', + 'ЫыЪъЭэ', + 'jαckγ', + ], + }); + }); + + it('should validate Hebrew alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'he' }], + valid: [ + 'אבג123', + 'שלום11', + ], + invalid: [ + 'אבג ', + 'לא!!', + 'abc', + ' foo ', + ], + }); + }); + + it('should validate Thai alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'th-TH' }], + valid: [ + 'สวัสดี ๑๒๓', + 'ยินดีต้อนรับทั้ง ๒ คน', + ], + invalid: [ + '1.สวัสดี', + 'ยินดีต้อนรับทั้ง 2 คน', + ], + }); + }); + + it('should validate Korea alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'ko-KR' }], + valid: [ + '2002', + '훈민정음', + '1446년훈민정음반포', + ], + invalid: [ + '2022!', + '2019 코로나시작', + '1.로렘입숨', + ], + }); + }); + + it('should validate Sinhala alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'si-LK' }], + valid: [ + 'චතුර', + 'කචට12', + 'ඎඏදාෛපසුගො2', + '1234', + ], + invalid: [ + 'ஆஐअतක', + 'කචට 12', + ' ඎ ', + 'a1234', + 'abc', + '', + ], + }); + }); + + it('should error on invalid locale', () => { + test({ + validator: 'isAlphanumeric', + args: [{ locale: 'is-NOT' }], + error: [ + '1234568960', + 'abc123', + ], + }); + }); + + describe('legacy', () => { + it('should validate alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + valid: [ + 'abc123', + 'ABC11', + ], + invalid: [ + 'abc ', + 'foo!!', + 'ÄBC', + 'FÜübar', + 'Jön', + ], + }); + }); + + it('should validate alphanumeric string with ignored characters', () => { + test({ + validator: 'isAlphanumeric', + args: ['en-US', { ignore: '@_- ' }], // ignore [@ space _ -] + valid: [ + 'Hello@123', + 'this is a valid alphaNumeric string', + 'En-US @ alpha_numeric', + ], + invalid: [ + 'In*Valid', + 'hello$123', + '{invalid}', + ], + }); + + test({ + validator: 'isAlphanumeric', + args: ['en-US', { ignore: /[\s/-]/g }], // ignore [space -] + valid: [ + 'en-US', + 'this is a valid alphaNumeric string', + ], + invalid: [ + 'INVALID$ AlphaNum Str', + 'hello@123', + 'abc*123', + ], + }); + + test({ + validator: 'isAlphanumeric', + args: ['en-US', { ignore: 1234 }], // invalid ignore matcher (ignore should be instance of a String or RegExp) + error: [ + 'alpha', + ], + }); + }); + + it('should validate defined english aliases', () => { + test({ + validator: 'isAlphanumeric', + args: ['en-GB'], + valid: [ + 'abc123', + 'ABC11', + ], + invalid: [ + 'abc ', + 'foo!!', + 'ÄBC', + 'FÜübar', + 'Jön', + ], + }); + }); + + 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', + args: ['bg-BG'], + valid: [ + 'абв1', + '4АБ5В6', + 'жаба', + 'яГоДа2', + 'йЮя', + '123', + ], + invalid: [ + ' ', + '789 ', + 'hello000', + ], + }); + }); + + it('should validate Bengali alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['bn-BD'], + valid: [ + 'দ্গজ্ঞহ্রত্য১২৩', + 'দ্গগফ৮৯০', + 'চব৩৬৫ভবচ', + '১২৩৪', + '৩৪২৩৪দফজ্ঞদফ', + ], + invalid: [ + ' ', + '১২৩ ', + 'hel৩২0', + ], + }); + }); + + it('should validate czech alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['cs-CZ'], + valid: [ + 'řiť123', + 'KŮŇ11', + ], + invalid: [ + 'řiď ', + 'blé!!', + ], + }); + }); + + it('should validate slovak alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['sk-SK'], + valid: [ + '1môj', + '2ľúbím', + '3mäkčeň', + '4stĹp', + '5vŕba', + '6ňorimberk', + '7ťava', + '8žanéta', + '9Ďábelské', + '10ódy', + ], + invalid: [ + '1moj!', + '你好世界', + ' Привет мир ', + ], + }); + }); + + it('should validate danish alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['da-DK'], + valid: [ + 'ÆØÅ123', + 'Ære321', + '321Øre', + '123Åre', + ], + invalid: [ + 'äbc123', + 'ÄBC11', + '', + ], + }); + }); + + it('should validate dutch alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['nl-NL'], + valid: [ + 'Kán123', + 'één354', + 'v4óór', + 'nú234', + 'hé54él', + ], + invalid: [ + '1äca ', + 'ab3cß', + 'Øre', + ], + }); + }); + + it('should validate finnish alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['fi-FI'], + valid: [ + 'äiti124', + 'ÖLJY1234', + '123Åke', + '451åå23', + ], + invalid: [ + 'AİıÖöÇ窺ĞğÜüZ', + 'foo!!', + '', + ], + }); + }); + + it('should validate german alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['de-DE'], + valid: [ + 'äbc123', + 'ÄBC11', + ], + invalid: [ + 'äca ', + 'föö!!', + ], + }); + }); + + it('should validate hungarian alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['hu-HU'], + valid: [ + '0árvíztűrőtükörfúrógép123', + '0ÁRVÍZTŰRŐTÜKÖRFÚRÓGÉP123', + ], + invalid: [ + '1időúr!', + 'äbc1', + ' fäö ', + 'Heiß!', + '', + ], + }); + }); + + it('should validate portuguese alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['pt-PT'], + valid: [ + 'palíndromo', + '2órgão', + 'qwértyúão9', + 'àäãcë4üïÄÏÜ', + ], + invalid: [ + '!abc', + 'Heiß', + 'Øre', + 'æøå', + '', + ], + }); + }); + + it('should validate italian alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['it-IT'], + valid: [ + '123àéèìîóòù', + '123correnti', + 'DEFINIZIONE321', + 'compil123azione', + 'met23ró', + 'pès56ca', + 'PÉS45CA', + 'gen45î', + ], + invalid: [ + 'äbc123', + 'ÄBC11', + 'æøå', + '', + ], + }); + }); + + it('should validate spanish alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['es-ES'], + valid: [ + 'ábcó123', + 'ÁBCÓ11', + ], + invalid: [ + 'äca ', + 'abcß', + 'föö!!', + ], + }); + }); + + it('should validate Vietnamese alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['vi-VN'], + valid: [ + 'Thầy3', + '3Gà', + ], + invalid: [ + 'toang!', + 'Cậu Vàng', + ], + }); + }); + + it('should validate arabic alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['ar'], + valid: [ + 'أبت123', + 'أبتَُِ١٢٣', + ], + invalid: [ + 'äca ', + 'abcß', + 'föö!!', + ], + }); + }); + + it('should validate Hindi alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['hi-IN'], + valid: [ + 'अतअपनाअपनीअपनेअभीअंदरआदिआपइत्यादिइनइनकाइन्हींइन्हेंइन्होंइसइसकाइसकीइसकेइसमेंइसीइसेउनउनकाउनकीउनकेउनकोउन्हींउन्हेंउन्होंउसउसकेउसीउसेएकएवंएसऐसेऔरकईकरकरताकरतेकरनाकरनेकरेंकहतेकहाकाकाफ़ीकिकितनाकिन्हेंकिन्होंकियाकिरकिसकिसीकिसेकीकुछकुलकेकोकोईकौनकौनसागयाघरजबजहाँजाजितनाजिनजिन्हेंजिन्होंजिसजिसेजीधरजैसाजैसेजोतकतबतरहतिनतिन्हेंतिन्होंतिसतिसेतोथाथीथेदबारादियादुसरादूसरेदोद्वाराननकेनहींनानिहायतनीचेनेपरपहलेपूरापेफिरबनीबहीबहुतबादबालाबिलकुलभीभीतरमगरमानोमेमेंयदियहयहाँयहीयायिहयेरखेंरहारहेऱ्वासालिएलियेलेकिनववग़ैरहवर्गवहवहाँवहींवालेवुहवेवोसकतासकतेसबसेसभीसाथसाबुतसाभसारासेसोसंगहीहुआहुईहुएहैहैंहोहोताहोतीहोतेहोनाहोने०२३४५६७८९', + 'इन्हें४५६७८९', + ], + invalid: [ + 'अत ०२३४५६७८९', + ' ३४५६७८९', + '12 ', + ' अत ', + 'abc1', + 'abc', + '', + ], + }); + }); + + it('should validate farsi alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['fa-IR'], + valid: [ + 'پارسی۱۲۳', + '۱۴۵۶', + 'مژگان9', + ], + invalid: [ + 'äca ', + 'abcßة', + 'föö!!', + '٤٥٦', + ], + }); + }); + + it('should validate Japanese alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['ja-JP'], + valid: [ + 'あいうえお123', + '123がぎぐげご', + 'ぁぃぅぇぉ', + 'アイウエオ', + 'ァィゥェ', + 'アイウエオ', + '20世紀少年', + '華氏451度', + ], + invalid: [ + ' あいう123 ', + 'abcあいう', + '生きろ!!', + ], + }); + }); + + it('should validate kurdish alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['ku-IQ'], + valid: [ + 'ئؤڤگێ١٢٣', + ], + invalid: [ + 'äca ', + 'abcß', + 'föö!!', + ], + }); + }); + + it('should validate defined arabic aliases', () => { + test({ + validator: 'isAlphanumeric', + args: ['ar-SY'], + valid: [ + 'أبت123', + 'أبتَُِ١٢٣', + ], + invalid: [ + 'abc ', + 'foo!!', + 'ÄBC', + 'FÜübar', + 'Jön', + ], + }); + }); + + it('should validate norwegian alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['nb-NO'], + valid: [ + 'ÆØÅ123', + 'Ære321', + '321Øre', + '123Åre', + ], + invalid: [ + 'äbc123', + 'ÄBC11', + '', + ], + }); + }); + + it('should validate polish alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['pl-PL'], + valid: [ + 'kre123ską', + 'zam21knięte', + 'zw23ykłe', + '123', + 'prz23yjęły', + 'świ23ęty', + 'Poz1322wól', + ], + invalid: [ + '12řiď ', + 'blé!!', + 'föö!2!', + ], + }); + }); + + it('should validate serbian cyrillic alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['sr-RS'], + valid: [ + 'ШћжЂљЕ123', + 'ЧПСТ132ЋЏ', + ], + invalid: [ + 'řiď ', + 'blé!!', + 'föö!!', + ], + }); + }); + + it('should validate serbian latin alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['sr-RS@latin'], + valid: [ + 'ŠAabčšđćž123', + 'ŠATRO11Ćčđš', + ], + invalid: [ + 'řiď ', + 'blé!!', + 'föö!!', + ], + }); + }); + + it('should validate swedish alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['sv-SE'], + valid: [ + 'religiös13', + 'st23jäla', + 'västgöte123', + '123Åre', + ], + invalid: [ + 'AİıÖöÇ窺ĞğÜüZ', + 'foo!!', + '', + ], + }); + }); + + it('should validate turkish alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['tr-TR'], + valid: [ + 'AİıÖöÇ窺ĞğÜüZ123', + ], + invalid: [ + 'AİıÖöÇ窺ĞğÜüZ ', + 'foo!!', + 'ÄBC', + ], + }); + }); + + it('should validate urkrainian alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['uk-UA'], + valid: [ + 'АБВГҐДЕЄЖЗИIЇЙКЛМНОПРСТУФХЦШЩЬЮЯ123', + ], + invalid: [ + 'éeoc ', + 'foo!!', + 'ÄBC', + 'ЫыЪъЭэ', + ], + }); + }); + + it('should validate greek alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['el-GR'], + valid: [ + 'αβγδεζηθικλμνξοπρςστυφχψω', + 'ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ', + '20θ', + '1234568960', + ], + invalid: [ + '0AİıÖöÇ窺ĞğÜüZ1', + ' AİıÖöÇ窺ĞğÜüZ ', + 'ÄBC', + 'Heiß', + 'ЫыЪъЭэ', + 'jαckγ', + ], + }); + }); + + it('should validate Hebrew alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['he'], + valid: [ + 'אבג123', + 'שלום11', + ], + invalid: [ + 'אבג ', + 'לא!!', + 'abc', + ' foo ', + ], + }); + }); + + it('should validate Thai alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['th-TH'], + valid: [ + 'สวัสดี ๑๒๓', + 'ยินดีต้อนรับทั้ง ๒ คน', + ], + invalid: [ + '1.สวัสดี', + 'ยินดีต้อนรับทั้ง 2 คน', + ], + }); + }); + + it('should validate Korea alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['ko-KR'], + valid: [ + '2002', + '훈민정음', + '1446년훈민정음반포', + ], + invalid: [ + '2022!', + '2019 코로나시작', + '1.로렘입숨', + ], + }); + }); + + it('should validate Sinhala alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['si-LK'], + valid: [ + 'චතුර', + 'කචට12', + 'ඎඏදාෛපසුගො2', + '1234', + ], + invalid: [ + 'ஆஐअतක', + 'කචට 12', + ' ඎ ', + 'a1234', + 'abc', + '', + ], + }); + }); + + it('should error on invalid locale', () => { + test({ + validator: 'isAlphanumeric', + args: ['is-NOT'], + error: [ + '1234568960', + 'abc123', + ], + }); + }); + }); +});