Fixed phone number validation.

Ylian Saint-Hilaire committed Nov 30, 2020 at 15:57 UTC 768c304b9ef1cbd350eaf8ae2bcd76a5e3eb664b
2 files changed +8 -2
meshuser.js
+7 -1
@@ -5144,7 +5144,13 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
5144 // Split a string taking into account the quoats. Used for command line parsing
5145 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; }
5146 function toNumberIfNumber(x) { if ((typeof x == 'string') && (+parseInt(x) === x)) { x = parseInt(x); } return x; }
5147 - 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})$/); }
5147 +
5148 + function isPhoneNumber(x) {
5149 + var ok = true;
5150 + if (x.startsWith('+')) { x = x.substring(1); }
5151 + 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; } }
5152 + return ok && (x.length >= 10);
5153 + }
5154
5155 function removeAllUnderScore(obj) {
5156 if (typeof obj != 'object') return obj;
views/default.handlebars
+1 -1
@@ -9192,7 +9192,7 @@
9192 }
9193 }
9194
9195 - 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})$/); }
9195 + 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); }
9196 function account_managePhoneValidate(x) { var ok = isPhoneNumber(Q('d2phoneinput').value); QE('idx_dlgOkButton', ok); if ((x == 1) && ok) { dialogclose(1); } }
9197 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); } }
9198 function account_managePhoneConfirm(b, tag) { meshserver.send({ action: 'confirmPhone', code: Q('d2phoneCodeInput').value, cookie: tag }); }