const imeiRx = /^\d{15}$/;
const IsValidImei = (imei) => {
if (!imeiRx.test(imei)) {
return false;
}
const mod10 = imei.split('')
.map((x) => parseInt(x.toString()))
.map((x, i) => i % 2 == 0 ? x : 2 * x)
.map(x => x >= 10 ? x - 9 : x)
.reduce((s, x) => s + x, 0)
% 10;
return (mod10 === 0);
}
Comments