From fd324df1c9fd60513e621e93383c8f32b7e057e7 Mon Sep 17 00:00:00 2001 From: Juan Date: Tue, 3 Apr 2018 16:54:41 +0200 Subject: [PATCH] #222 - DNI validation bug solved --- services/loopback/common/locale/en.json | 3 ++- services/loopback/common/validations/validateTin.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/services/loopback/common/locale/en.json b/services/loopback/common/locale/en.json index 288480f559..cc493531ce 100644 --- a/services/loopback/common/locale/en.json +++ b/services/loopback/common/locale/en.json @@ -7,5 +7,6 @@ "El método de pago seleccionado requiere que se especifique el IBAN": "El método de pago seleccionado requiere que se especifique el IBAN", "Ya existe un usuario con ese nombre": "Ya existe un usuario con ese nombre", "Quantity cannot be zero": "Quantity cannot be zero", - "can't be blank": "can't be blank" + "can't be blank": "can't be blank", + "DNI Incorrecto": "DNI Incorrecto" } \ No newline at end of file diff --git a/services/loopback/common/validations/validateTin.js b/services/loopback/common/validations/validateTin.js index ae1c38ceed..ddc3fcf63b 100644 --- a/services/loopback/common/validations/validateTin.js +++ b/services/loopback/common/validations/validateTin.js @@ -37,8 +37,8 @@ module.exports = function(tin, country) { let sum = (pairSum + oddSum).toString(); let units = parseInt(sum.charAt(sum.length - 1)); let control = units == 0 ? 0 : 10 - units; - let index = 'JABCDEFGHI'.indexOf(lastDigit); - computedDigit = index == -1 ? control.toString() : index; + let isLetter = /^[A-Z]$/.test(lastDigit); + computedDigit = isLetter ? 'JABCDEFGHI'.charAt(control) : control.toString(); } else { // Foreign NIF let index = 'XYZ'.indexOf(tin.charAt(0));