Skip to content

Commit

Permalink
feat: adds fixes and tests for #679
Browse files Browse the repository at this point in the history
This commit adds minor fixes on the PR #679
completing alpha, alphanumeric and mobile-phone
features for Greece.
  • Loading branch information
profnandaa committed Dec 8, 2017
1 parent 7df6c5d commit e4bb8df
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 12 deletions.
8 changes: 4 additions & 4 deletions lib/alpha.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Object.defineProperty(exports, "__esModule", {
});
var alpha = exports.alpha = {
'en-US': /^[A-Z]+$/i,
'el-GR': /^[Α-Ω]+$/i,
'cs-CZ': /^[A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i,
'da-DK': /^[A-ZÆØÅ]+$/i,
'de-DE': /^[A-ZÄÖÜß]+$/i,
'el-GR': /^[Α-ω]+$/i,
'es-ES': /^[A-ZÁÉÍÑÓÚÜ]+$/i,
'fr-FR': /^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
'it-IT': /^[A-ZÀÉÈÌÎÓÒÙ]+$/i,
Expand All @@ -29,10 +29,10 @@ var alpha = exports.alpha = {

var alphanumeric = exports.alphanumeric = {
'en-US': /^[0-9A-Z]+$/i,
'el-GR': /^[Α-Ω]+$/i,
'cs-CZ': /^[0-9A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i,
'da-DK': /^[0-9A-ZÆØÅ]+$/i,
'de-DE': /^[0-9A-ZÄÖÜß]+$/i,
'el-GR': /^[0-9Α-ω]+$/i,
'es-ES': /^[0-9A-ZÁÉÍÑÓÚÜ]+$/i,
'fr-FR': /^[0-9A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
'it-IT': /^[0-9A-ZÀÉÈÌÎÓÒÙ]+$/i,
Expand Down Expand Up @@ -77,7 +77,7 @@ for (var _locale, _i = 0; _i < arabicLocales.length; _i++) {

// Source: https://en.wikipedia.org/wiki/Decimal_mark
var dotDecimal = exports.dotDecimal = [];
var commaDecimal = exports.commaDecimal = ['cs-CZ', 'da-DK', 'de-DE', 'es-ES', 'fr-FR', 'it-IT', 'hu-HU', 'nb-NO', 'nn-NO', 'nl-NL', 'pl-Pl', 'pt-PT', 'ru-RU', 'sr-RS@latin', 'sr-RS', 'sv-SE', 'tr-TR', 'uk-UA'];
var commaDecimal = exports.commaDecimal = ['cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'es-ES', 'fr-FR', 'it-IT', 'hu-HU', 'nb-NO', 'nn-NO', 'nl-NL', 'pl-Pl', 'pt-PT', 'ru-RU', 'sr-RS@latin', 'sr-RS', 'sv-SE', 'tr-TR', 'uk-UA'];

for (var _i2 = 0; _i2 < dotDecimal.length; _i2++) {
decimal[dotDecimal[_i2]] = decimal['en-US'];
Expand All @@ -89,4 +89,4 @@ for (var _i3 = 0; _i3 < commaDecimal.length; _i3++) {

alpha['pt-BR'] = alpha['pt-PT'];
alphanumeric['pt-BR'] = alphanumeric['pt-PT'];
decimal['pt-BR'] = decimal['pt-PT'];
decimal['pt-BR'] = decimal['pt-PT'];
5 changes: 2 additions & 3 deletions lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ var phones = {
'cs-CZ': /^(\+?420)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
'da-DK': /^(\+?45)?\s?\d{2}\s?\d{2}\s?\d{2}\s?\d{2}$/,
'de-DE': /^(\+?49[ \.\-])?([\(]{1}[0-9]{1,6}[\)])?([0-9 \.\-\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$/,
'el-GR': /^(\+?30)?(69\d{8})$/,
'el-CY': /^(\+?357?)?(9\d{7})$/,
'el-GR': /^(\+?30|0)?(69\d{8})$/,
'en-AU': /^(\+?61|0)4\d{8}$/,
'en-GB': /^(\+?44|0)7\d{9}$/,
'en-HK': /^(\+?852\-?)?[456789]\d{3}\-?\d{4}$/,
Expand Down Expand Up @@ -94,4 +93,4 @@ function isMobilePhone(str, locale) {
}
throw new Error('Invalid locale \'' + locale + '\'');
}
module.exports = exports['default'];
module.exports = exports['default'];
4 changes: 3 additions & 1 deletion src/lib/alpha.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const alpha = {
'cs-CZ': /^[A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i,
'da-DK': /^[A-ZÆØÅ]+$/i,
'de-DE': /^[A-ZÄÖÜß]+$/i,
'el-GR': /^[Α-ω]+$/i,
'es-ES': /^[A-ZÁÉÍÑÓÚÜ]+$/i,
'fr-FR': /^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
'it-IT': /^[A-ZÀÉÈÌÎÓÒÙ]+$/i,
Expand All @@ -26,6 +27,7 @@ export const alphanumeric = {
'cs-CZ': /^[0-9A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i,
'da-DK': /^[0-9A-ZÆØÅ]+$/i,
'de-DE': /^[0-9A-ZÄÖÜß]+$/i,
'el-GR': /^[0-9Α-ω]+$/i,
'es-ES': /^[0-9A-ZÁÉÍÑÓÚÜ]+$/i,
'fr-FR': /^[0-9A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
'it-IT': /^[0-9A-ZÀÉÈÌÎÓÒÙ]+$/i,
Expand Down Expand Up @@ -75,7 +77,7 @@ for (let locale, i = 0; i < arabicLocales.length; i++) {
// Source: https://en.wikipedia.org/wiki/Decimal_mark
export const dotDecimal = [];
export const commaDecimal = [
'cs-CZ', 'da-DK', 'de-DE', 'es-ES', 'fr-FR', 'it-IT', 'hu-HU', 'nb-NO',
'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'es-ES', 'fr-FR', 'it-IT', 'hu-HU', 'nb-NO',
'nn-NO', 'nl-NL', 'pl-Pl', 'pt-PT', 'ru-RU', 'sr-RS@latin',
'sr-RS', 'sv-SE', 'tr-TR', 'uk-UA',
];
Expand Down
2 changes: 1 addition & 1 deletion src/lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const phones = {
'cs-CZ': /^(\+?420)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
'da-DK': /^(\+?45)?\s?\d{2}\s?\d{2}\s?\d{2}\s?\d{2}$/,
'de-DE': /^(\+?49[ \.\-])?([\(]{1}[0-9]{1,6}[\)])?([0-9 \.\-\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$/,
'el-GR': /^(\+?30)?(69\d{8})$/,
'el-GR': /^(\+?30|0)?(69\d{8})$/,
'en-AU': /^(\+?61|0)4\d{8}$/,
'en-GB': /^(\+?44|0)7\d{9}$/,
'en-HK': /^(\+?852\-?)?[456789]\d{3}\-?\d{4}$/,
Expand Down
41 changes: 41 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,26 @@ describe('Validators', function () {
});
});

it('should validate greek alpha strings', function () {
test({
validator: 'isAlpha',
args: ['el-GR'],
valid: [
'αβγδεζηθικλμνξοπρςστυφχψω',
'ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ',
],
invalid: [
'0AİıÖöÇ窺ĞğÜüZ1',
' AİıÖöÇ窺ĞğÜüZ ',
'ÄBC',
'Heiß',
'ЫыЪъЭэ',
'120',
'jαckγ',
],
});
});

it('should validate alphanumeric strings', function () {
test({
validator: 'isAlphanumeric',
Expand Down Expand Up @@ -1310,6 +1330,27 @@ describe('Validators', function () {
});
});

it('should validate greek alphanumeric strings', function () {
test({
validator: 'isAlphanumeric',
args: ['el-GR'],
valid: [
'αβγδεζηθικλμνξοπρςστυφχψω',
'ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ',
'20θ',
'1234568960',
],
invalid: [
'0AİıÖöÇ窺ĞğÜüZ1',
' AİıÖöÇ窺ĞğÜüZ ',
'ÄBC',
'Heiß',
'ЫыЪъЭэ',
'jαckγ',
],
});
});

it('should error on invalid locale', function () {
try {
validator.isAlphanumeric('abc123', 'in-INVALID');
Expand Down
6 changes: 4 additions & 2 deletions validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ var alpha = {
'cs-CZ': /^[A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i,
'da-DK': /^[A-ZÆØÅ]+$/i,
'de-DE': /^[A-ZÄÖÜß]+$/i,
'el-GR': /^[Α-ω]+$/i,
'es-ES': /^[A-ZÁÉÍÑÓÚÜ]+$/i,
'fr-FR': /^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
'it-IT': /^[A-ZÀÉÈÌÎÓÒÙ]+$/i,
Expand All @@ -462,6 +463,7 @@ var alphanumeric = {
'cs-CZ': /^[0-9A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i,
'da-DK': /^[0-9A-ZÆØÅ]+$/i,
'de-DE': /^[0-9A-ZÄÖÜß]+$/i,
'el-GR': /^[0-9Α-ω]+$/i,
'es-ES': /^[0-9A-ZÁÉÍÑÓÚÜ]+$/i,
'fr-FR': /^[0-9A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
'it-IT': /^[0-9A-ZÀÉÈÌÎÓÒÙ]+$/i,
Expand Down Expand Up @@ -506,7 +508,7 @@ for (var _locale, _i = 0; _i < arabicLocales.length; _i++) {

// Source: https://en.wikipedia.org/wiki/Decimal_mark
var dotDecimal = [];
var commaDecimal = ['cs-CZ', 'da-DK', 'de-DE', 'es-ES', 'fr-FR', 'it-IT', 'hu-HU', 'nb-NO', 'nn-NO', 'nl-NL', 'pl-Pl', 'pt-PT', 'ru-RU', 'sr-RS@latin', 'sr-RS', 'sv-SE', 'tr-TR', 'uk-UA'];
var commaDecimal = ['cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'es-ES', 'fr-FR', 'it-IT', 'hu-HU', 'nb-NO', 'nn-NO', 'nl-NL', 'pl-Pl', 'pt-PT', 'ru-RU', 'sr-RS@latin', 'sr-RS', 'sv-SE', 'tr-TR', 'uk-UA'];

for (var _i2 = 0; _i2 < dotDecimal.length; _i2++) {
decimal[dotDecimal[_i2]] = decimal['en-US'];
Expand Down Expand Up @@ -969,7 +971,7 @@ var phones = {
'cs-CZ': /^(\+?420)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
'da-DK': /^(\+?45)?\s?\d{2}\s?\d{2}\s?\d{2}\s?\d{2}$/,
'de-DE': /^(\+?49[ \.\-])?([\(]{1}[0-9]{1,6}[\)])?([0-9 \.\-\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$/,
'el-GR': /^(\+?30)?(69\d{8})$/,
'el-GR': /^(\+?30|0)?(69\d{8})$/,
'en-AU': /^(\+?61|0)4\d{8}$/,
'en-GB': /^(\+?44|0)7\d{9}$/,
'en-HK': /^(\+?852\-?)?[456789]\d{3}\-?\d{4}$/,
Expand Down
2 changes: 1 addition & 1 deletion validator.min.js

Large diffs are not rendered by default.

0 comments on commit e4bb8df

Please sign in to comment.