From 768c304b9ef1cbd350eaf8ae2bcd76a5e3eb664b Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Mon, 30 Nov 2020 15:57:16 -0800 Subject: [PATCH] Fixed phone number validation. --- meshuser.js | 8 +++++++- views/default.handlebars | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/meshuser.js b/meshuser.js index 59f2db94..0ec18cb6 100644 --- a/meshuser.js +++ b/meshuser.js @@ -5144,7 +5144,13 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use // Split a string taking into account the quoats. Used for command line parsing function splitArgs(str) { var myArray = [], myRegexp = /[^\s"]+|"([^"]*)"/gi; do { var match = myRegexp.exec(str); if (match != null) { myArray.push(match[1] ? match[1] : match[0]); } } while (match != null); return myArray; } function toNumberIfNumber(x) { if ((typeof x == 'string') && (+parseInt(x) === x)) { x = parseInt(x); } return x; } - function isPhoneNumber(x) { return x.match(/^\d{10}$/) || x.match(/^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/) || x.match(/^\+?([0-9]{2})\)?[-. ]?([0-9]{4})[-. ]?([0-9]{4})$/); } + + function isPhoneNumber(x) { + var ok = true; + if (x.startsWith('+')) { x = x.substring(1); } + for (var i = 0; i < x.length; i++) { var c = x.charCodeAt(i); if (((c < 48) || (c > 57)) && (c != 32) && (c != 45) && (c != 46)) { ok = false; } } + return ok && (x.length >= 10); + } function removeAllUnderScore(obj) { if (typeof obj != 'object') return obj; diff --git a/views/default.handlebars b/views/default.handlebars index fd2476e9..eab7fddd 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -9192,7 +9192,7 @@ } } - function isPhoneNumber(x) { return x.match(/^\d{10}$/) || x.match(/^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/) || x.match(/^\+?([0-9]{2})\)?[-. ]?([0-9]{4})[-. ]?([0-9]{4})$/); } + function isPhoneNumber(x) { var ok = true; if (x.startsWith('+')) { x = x.substring(1); } for (var i = 0; i < x.length; i++) { var c = x.charCodeAt(i); if (((c < 48) || (c > 57)) && (c != 32) && (c != 45) && (c != 46)) { ok = false; } } return ok && (x.length >= 10); } function account_managePhoneValidate(x) { var ok = isPhoneNumber(Q('d2phoneinput').value); QE('idx_dlgOkButton', ok); if ((x == 1) && ok) { dialogclose(1); } } function account_managePhoneCodeValidate(x) { var ok = (Q('d2phoneCodeInput').value.length == 6) && Q('d2phoneCodeInput').value.match(/[0-9]/); QE('idx_dlgOkButton', ok); if ((x == 1) && ok) { dialogclose(1); } } function account_managePhoneConfirm(b, tag) { meshserver.send({ action: 'confirmPhone', code: Q('d2phoneCodeInput').value, cookie: tag }); }