Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(isMobilePhone): update bn-BD validation #1032

Merged
merged 2 commits into from
May 23, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
var phones = {
'ar-AE': /^((\+?971)|0)?5[024568]\d{7}$/,
'ar-DZ': /^(\+?213|0)(5|6|7)\d{8}$/,
'ar-EG': /^((\+?20)|0)?1[012]\d{8}$/,
'ar-EG': /^((\+?20)|0)?1[0125]\d{8}$/,
'ar-IQ': /^(\+?964|0)?7[0-9]\d{8}$/,
'ar-JO': /^(\+?962|0)?7[789]\d{7}$/,
'ar-KW': /^(\+?965)[569]\d{7}$/,
Expand All @@ -23,7 +23,7 @@ var phones = {
'ar-TN': /^(\+?216)?[2459]\d{7}$/,
'be-BY': /^(\+?375)?(24|25|29|33|44)\d{7}$/,
'bg-BG': /^(\+?359|0)?8[789]\d{7}$/,
'bn-BD': /\+?(88)?0?1[356789][0-9]{8}\b/,
'bn-BD': /^(\+?880|0)1[1356789][0-9]{8}$/,
'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)?0?1(5[0-25-9]\d|6([23]|0\d?)|7([0-57-9]|6\d))\d{7}$/,
Expand All @@ -48,6 +48,7 @@ var phones = {
'en-ZM': /^(\+?26)?09[567]\d{7}$/,
'es-ES': /^(\+?34)?(6\d{1}|7[1234])\d{7}$/,
'es-MX': /^(\+?52)?(1|01)?\d{10,11}$/,
'es-PY': /^(\+?595|0)9[9876]\d{7}$/,
'es-UY': /^(\+598|0)9[1-9][\d]{6}$/,
'et-EE': /^(\+?372)?\s?(5|8[1-4])\s?([0-9]\s?){6,7}$/,
'fa-IR': /^(\+?98[\-\s]?|0)9[0-39]\d[\-\s]?\d{3}[\-\s]?\d{4}$/,
Expand Down
1 change: 1 addition & 0 deletions lib/isPostalCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var patterns = {
GR: /^\d{3}\s?\d{2}$/,
HR: /^([1-5]\d{4}$)/,
HU: fourDigit,
ID: fiveDigit,
IL: fiveDigit,
IN: sixDigit,
IS: threeDigit,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const phones = {
'ar-TN': /^(\+?216)?[2459]\d{7}$/,
'be-BY': /^(\+?375)?(24|25|29|33|44)\d{7}$/,
'bg-BG': /^(\+?359|0)?8[789]\d{7}$/,
'bn-BD': /\+?(88)?0?1[356789][0-9]{8}\b/,
'bn-BD': /^(\+?880|0)1[1356789][0-9]{8}$/,
'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)?0?1(5[0-25-9]\d|6([23]|0\d?)|7([0-57-9]|6\d))\d{7}$/,
Expand Down
3 changes: 3 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -3514,13 +3514,16 @@ describe('Validators', () => {
'01399098893',
'8801671163269',
'01717112029',
'8801898765432',
'+8801312345678',
],
invalid: [
'',
'0174626346',
'017943563469',
'18001234567',
'01494676946',
'0131234567',
],
},
{
Expand Down
208 changes: 13 additions & 195 deletions validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,191 +40,6 @@ function _typeof(obj) {
return _typeof(obj);
}

function _toArray(arr) {
return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest();
}

function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}

function _iterableToArray(iter) {
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
}

function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
}

function _toPrimitive(input, hint) {
if (typeof input !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];

if (prim !== undefined) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object") return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}

return (hint === "string" ? String : Number)(input);
}

function _toPropertyKey(arg) {
var key = _toPrimitive(arg, "string");

return typeof key === "symbol" ? key : String(key);
}

function _addElementPlacement(element, placements, silent) {
var keys = placements[element.placement];

if (!silent && keys.indexOf(element.key) !== -1) {
throw new TypeError("Duplicated element (" + element.key + ")");
}

keys.push(element.key);
}

function _fromElementDescriptor(element) {
var obj = {
kind: element.kind,
key: element.key,
placement: element.placement,
descriptor: element.descriptor
};
var desc = {
value: "Descriptor",
configurable: true
};
Object.defineProperty(obj, Symbol.toStringTag, desc);
if (element.kind === "field") obj.initializer = element.initializer;
return obj;
}

function _toElementDescriptors(elementObjects) {
if (elementObjects === undefined) return;
return _toArray(elementObjects).map(function (elementObject) {
var element = _toElementDescriptor(elementObject);

_disallowProperty(elementObject, "finisher", "An element descriptor");

_disallowProperty(elementObject, "extras", "An element descriptor");

return element;
});
}

function _toElementDescriptor(elementObject) {
var kind = String(elementObject.kind);

if (kind !== "method" && kind !== "field") {
throw new TypeError('An element descriptor\'s .kind property must be either "method" or' + ' "field", but a decorator created an element descriptor with' + ' .kind "' + kind + '"');
}

var key = _toPropertyKey(elementObject.key);

var placement = String(elementObject.placement);

if (placement !== "static" && placement !== "prototype" && placement !== "own") {
throw new TypeError('An element descriptor\'s .placement property must be one of "static",' + ' "prototype" or "own", but a decorator created an element descriptor' + ' with .placement "' + placement + '"');
}

var descriptor = elementObject.descriptor;

_disallowProperty(elementObject, "elements", "An element descriptor");

var element = {
kind: kind,
key: key,
placement: placement,
descriptor: Object.assign({}, descriptor)
};

if (kind !== "field") {
_disallowProperty(elementObject, "initializer", "A method descriptor");
} else {
_disallowProperty(descriptor, "get", "The property descriptor of a field descriptor");

_disallowProperty(descriptor, "set", "The property descriptor of a field descriptor");

_disallowProperty(descriptor, "value", "The property descriptor of a field descriptor");

element.initializer = elementObject.initializer;
}

return element;
}

function _toElementFinisherExtras(elementObject) {
var element = _toElementDescriptor(elementObject);

var finisher = _optionalCallableProperty(elementObject, "finisher");

var extras = _toElementDescriptors(elementObject.extras);

return {
element: element,
finisher: finisher,
extras: extras
};
}

function _fromClassDescriptor(elements) {
var obj = {
kind: "class",
elements: elements.map(_fromElementDescriptor)
};
var desc = {
value: "Descriptor",
configurable: true
};
Object.defineProperty(obj, Symbol.toStringTag, desc);
return obj;
}

function _toClassDescriptor(obj) {
var kind = String(obj.kind);

if (kind !== "class") {
throw new TypeError('A class descriptor\'s .kind property must be "class", but a decorator' + ' created a class descriptor with .kind "' + kind + '"');
}

_disallowProperty(obj, "key", "A class descriptor");

_disallowProperty(obj, "placement", "A class descriptor");

_disallowProperty(obj, "descriptor", "A class descriptor");

_disallowProperty(obj, "initializer", "A class descriptor");

_disallowProperty(obj, "extras", "A class descriptor");

var finisher = _optionalCallableProperty(obj, "finisher");

var elements = _toElementDescriptors(obj.elements);

return {
elements: elements,
finisher: finisher
};
}

function _disallowProperty(obj, name, objectType) {
if (obj[name] !== undefined) {
throw new TypeError(objectType + " can't have a ." + name + " property.");
}
}

function _optionalCallableProperty(obj, name) {
var value = obj[name];

if (value !== undefined && typeof value !== "function") {
throw new TypeError("Expected '" + name + "' to be a function");
}

return value;
}

function assertString(input) {
var isString = typeof input === 'string' || input instanceof String;

Expand Down Expand Up @@ -887,14 +702,14 @@ function isNumeric(str, options) {
return numeric.test(str);
}

var int = /^(?:[-+]?(?:0|[1-9][0-9]*))$/;
var _int = /^(?:[-+]?(?:0|[1-9][0-9]*))$/;
var intLeadingZeroes = /^[-+]?[0-9]+$/;
function isInt(str, options) {
assertString(str);
options = options || {}; // Get the regex to use for testing, based on whether
// leading zeroes are allowed or not.

var regex = options.hasOwnProperty('allow_leading_zeroes') && !options.allow_leading_zeroes ? int : intLeadingZeroes; // Check min/max/lt/gt
var regex = options.hasOwnProperty('allow_leading_zeroes') && !options.allow_leading_zeroes ? _int : intLeadingZeroes; // Check min/max/lt/gt

var minCheckPassed = !options.hasOwnProperty('min') || str >= options.min;
var maxCheckPassed = !options.hasOwnProperty('max') || str <= options.max;
Expand Down Expand Up @@ -966,14 +781,15 @@ function isSurrogatePair(str) {
function isFloat(str, options) {
assertString(str);
options = options || {};
var float = new RegExp("^(?:[-+])?(?:[0-9]+)?(?:\\".concat(options.locale ? decimal[options.locale] : '.', "[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$"));

var _float = new RegExp("^(?:[-+])?(?:[0-9]+)?(?:\\".concat(options.locale ? decimal[options.locale] : '.', "[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$"));

if (str === '' || str === '.' || str === '-' || str === '+') {
return false;
}

var value = parseFloat(str.replace(',', '.'));
return float.test(str) && (!options.hasOwnProperty('min') || value >= options.min) && (!options.hasOwnProperty('max') || value <= options.max) && (!options.hasOwnProperty('lt') || value < options.lt) && (!options.hasOwnProperty('gt') || value > options.gt);
return _float.test(str) && (!options.hasOwnProperty('min') || value >= options.min) && (!options.hasOwnProperty('max') || value <= options.max) && (!options.hasOwnProperty('lt') || value < options.lt) && (!options.hasOwnProperty('gt') || value > options.gt);
}
var locales$2 = Object.keys(decimal);

Expand Down Expand Up @@ -1219,8 +1035,8 @@ var validators = {
} // validate the control digit


var number = sanitized.slice(0, -1).replace(/[X,Y,Z]/g, function (char) {
return charsValue[char];
var number = sanitized.slice(0, -1).replace(/[X,Y,Z]/g, function (_char) {
return charsValue[_char];
});
return sanitized.endsWith(controlDigits[number % 23]);
}
Expand Down Expand Up @@ -1365,7 +1181,7 @@ function isISSN(str) {
var phones = {
'ar-AE': /^((\+?971)|0)?5[024568]\d{7}$/,
'ar-DZ': /^(\+?213|0)(5|6|7)\d{8}$/,
'ar-EG': /^((\+?20)|0)?1[012]\d{8}$/,
'ar-EG': /^((\+?20)|0)?1[0125]\d{8}$/,
'ar-IQ': /^(\+?964|0)?7[0-9]\d{8}$/,
'ar-JO': /^(\+?962|0)?7[789]\d{7}$/,
'ar-KW': /^(\+?965)[569]\d{7}$/,
Expand All @@ -1374,7 +1190,7 @@ var phones = {
'ar-TN': /^(\+?216)?[2459]\d{7}$/,
'be-BY': /^(\+?375)?(24|25|29|33|44)\d{7}$/,
'bg-BG': /^(\+?359|0)?8[789]\d{7}$/,
'bn-BD': /\+?(88)?0?1[356789][0-9]{8}\b/,
'bn-BD': /^(\+?880|0)1[1356789][0-9]{8}$/,
'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)?0?1(5[0-25-9]\d|6([23]|0\d?)|7([0-57-9]|6\d))\d{7}$/,
Expand All @@ -1399,6 +1215,7 @@ var phones = {
'en-ZM': /^(\+?26)?09[567]\d{7}$/,
'es-ES': /^(\+?34)?(6\d{1}|7[1234])\d{7}$/,
'es-MX': /^(\+?52)?(1|01)?\d{10,11}$/,
'es-PY': /^(\+?595|0)9[9876]\d{7}$/,
'es-UY': /^(\+598|0)9[1-9][\d]{6}$/,
'et-EE': /^(\+?372)?\s?(5|8[1-4])\s?([0-9]\s?){6,7}$/,
'fa-IR': /^(\+?98[\-\s]?|0)9[0-39]\d[\-\s]?\d{3}[\-\s]?\d{4}$/,
Expand Down Expand Up @@ -1729,12 +1546,12 @@ function isMimeType(str) {
}

var lat = /^\(?[+-]?(90(\.0+)?|[1-8]?\d(\.\d+)?)$/;
var long = /^\s?[+-]?(180(\.0+)?|1[0-7]\d(\.\d+)?|\d{1,2}(\.\d+)?)\)?$/;
var _long = /^\s?[+-]?(180(\.0+)?|1[0-7]\d(\.\d+)?|\d{1,2}(\.\d+)?)\)?$/;
var isLatLong = function (str) {
assertString(str);
if (!str.includes(',')) return false;
var pair = str.split(',');
return lat.test(pair[0]) && long.test(pair[1]);
return lat.test(pair[0]) && _long.test(pair[1]);
};

var threeDigit = /^\d{3}$/;
Expand All @@ -1761,6 +1578,7 @@ var patterns = {
GR: /^\d{3}\s?\d{2}$/,
HR: /^([1-5]\d{4}$)/,
HU: fourDigit,
ID: fiveDigit,
IL: fiveDigit,
IN: sixDigit,
IS: threeDigit,
Expand Down
2 changes: 1 addition & 1 deletion validator.min.js

Large diffs are not rendered by default.