Skip to content

Commit

Permalink
Merge pull request #700 from mika-s/master
Browse files Browse the repository at this point in the history
Add Italian locale for isAlpha() and isAlphanumeric. Update readme.
  • Loading branch information
chriso authored Aug 23, 2017
2 parents 225bc3d + 4df957d commit ef09341
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ Passing anything other than a string is an error.
- **contains(str, seed)** - check if the string contains the seed.
- **equals(str, comparison)** - check if the string matches the comparison.
- **isAfter(str [, date])** - check if the string is a date that's after the specified date (defaults to now).
- **isAlpha(str [, locale])** - check if the string contains only letters (a-zA-Z). Locale is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'cs-CZ', 'da-DK', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', 'hu-HU', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sr-RS', 'sr-RS@latin', 'tr-TR', 'uk-UA']`) and defaults to `en-US`.
- **isAlphanumeric(str [, locale])** - check if the string contains only letters and numbers. Locale is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'cs-CZ', 'da-DK', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', 'fr-BE', 'hu-HU', 'nl-BE', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sr-RS', 'sr-RS@latin', 'tr-TR', 'uk-UA']`) and defaults to `en-US`.
- **isAlpha(str [, locale])** - check if the string contains only letters (a-zA-Z). Locale is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'cs-CZ', 'da-DK', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', 'hu-HU', 'it-IT', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sr-RS', 'sr-RS@latin', 'tr-TR', 'uk-UA']`) and defaults to `en-US`.
- **isAlphanumeric(str [, locale])** - check if the string contains only letters and numbers. Locale is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'cs-CZ', 'da-DK', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', 'hu-HU', 'it-IT', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sr-RS', 'sr-RS@latin', 'tr-TR', 'uk-UA']`) and defaults to `en-US`.
- **isAscii(str)** - check if the string contains ASCII chars only.
- **isBase64(str)** - check if a string is base64 encoded.
- **isBefore(str [, date])** - check if the string is a date that's before the specified date.
Expand Down
2 changes: 2 additions & 0 deletions lib/alpha.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var alpha = exports.alpha = {
'de-DE': /^[A-ZÄÖÜß]+$/i,
'es-ES': /^[A-ZÁÉÍÑÓÚÜ]+$/i,
'fr-FR': /^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
'it-IT': /^[A-ZÀÉÈÌÎÓÒÙ]+$/i,
'nb-NO': /^[A-ZÆØÅ]+$/i,
'nl-NL': /^[A-ZÉËÏÓÖÜ]+$/i,
'nn-NO': /^[A-ZÆØÅ]+$/i,
Expand All @@ -31,6 +32,7 @@ var alphanumeric = exports.alphanumeric = {
'de-DE': /^[0-9A-ZÄÖÜß]+$/i,
'es-ES': /^[0-9A-ZÁÉÍÑÓÚÜ]+$/i,
'fr-FR': /^[0-9A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
'it-IT': /^[0-9A-ZÀÉÈÌÎÓÒÙ]+$/i,
'hu-HU': /^[0-9A-ZÁÉÍÓÖŐÚÜŰ]+$/i,
'nb-NO': /^[0-9A-ZÆØÅ]+$/i,
'nl-NL': /^[0-9A-ZÉËÏÓÖÜ]+$/i,
Expand Down
2 changes: 2 additions & 0 deletions src/lib/alpha.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const alpha = {
'de-DE': /^[A-ZÄÖÜß]+$/i,
'es-ES': /^[A-ZÁÉÍÑÓÚÜ]+$/i,
'fr-FR': /^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
'it-IT': /^[A-ZÀÉÈÌÎÓÒÙ]+$/i,
'nb-NO': /^[A-ZÆØÅ]+$/i,
'nl-NL': /^[A-ZÉËÏÓÖÜ]+$/i,
'nn-NO': /^[A-ZÆØÅ]+$/i,
Expand All @@ -26,6 +27,7 @@ export const alphanumeric = {
'de-DE': /^[0-9A-ZÄÖÜß]+$/i,
'es-ES': /^[0-9A-ZÁÉÍÑÓÚÜ]+$/i,
'fr-FR': /^[0-9A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
'it-IT': /^[0-9A-ZÀÉÈÌÎÓÒÙ]+$/i,
'hu-HU': /^[0-9A-ZÁÉÍÓÖŐÚÜŰ]+$/i,
'nb-NO': /^[0-9A-ZÆØÅ]+$/i,
'nl-NL': /^[0-9A-ZÉËÏÓÖÜ]+$/i,
Expand Down
46 changes: 46 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,29 @@ describe('Validators', function () {
});
});

it('should validate italian alpha strings', function () {
test({
validator: 'isAlpha',
args: ['it-IT'],
valid: [
'àéèìîóòù',
'correnti',
'DEFINIZIONE',
'compilazione',
'metró',
'pèsca',
'PÉSCA',
'genî',
],
invalid: [
'äbc123',
'ÄBC11',
'æøå',
'',
],
});
});

it('should validate arabic alpha strings', function () {
test({
validator: 'isAlpha',
Expand Down Expand Up @@ -999,6 +1022,29 @@ describe('Validators', function () {
});
});

it('should validate italian alphanumeric strings', function () {
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', function () {
test({
validator: 'isAlphanumeric',
Expand Down
2 changes: 2 additions & 0 deletions validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ var alpha = {
'de-DE': /^[A-ZÄÖÜß]+$/i,
'es-ES': /^[A-ZÁÉÍÑÓÚÜ]+$/i,
'fr-FR': /^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
'it-IT': /^[A-ZÀÉÈÌÎÓÒÙ]+$/i,
'nb-NO': /^[A-ZÆØÅ]+$/i,
'nl-NL': /^[A-ZÉËÏÓÖÜ]+$/i,
'nn-NO': /^[A-ZÆØÅ]+$/i,
Expand All @@ -462,6 +463,7 @@ var alphanumeric = {
'de-DE': /^[0-9A-ZÄÖÜß]+$/i,
'es-ES': /^[0-9A-ZÁÉÍÑÓÚÜ]+$/i,
'fr-FR': /^[0-9A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
'it-IT': /^[0-9A-ZÀÉÈÌÎÓÒÙ]+$/i,
'hu-HU': /^[0-9A-ZÁÉÍÓÖŐÚÜŰ]+$/i,
'nb-NO': /^[0-9A-ZÆØÅ]+$/i,
'nl-NL': /^[0-9A-ZÉËÏÓÖÜ]+$/i,
Expand Down
76 changes: 75 additions & 1 deletion validator.min.js

Large diffs are not rendered by default.

0 comments on commit ef09341

Please sign in to comment.