Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Función para validar el CUPS (Código Unificado de Punto de Suministro)
function validarCUPS(CUPS) {
let ret = false;
const reCUPS = /^[A-Z]{2}(\d{4}\d{12})([A-Z]{2})(\d[FPCRXYZ])?$/i;
if (reCUPS.test(CUPS)) {
const mCUPS = CUPS.toUpperCase().match(reCUPS);
const cups16 = mCUPS[1],
control = mCUPS[2],
letters = [
'T', 'R', 'W', 'A', 'G', 'M',
'Y', 'F', 'P', 'D', 'X', 'B',
'N', 'J', 'Z', 'S', 'Q', 'V',
'H', 'L', 'C', 'K', 'E',
const cup16Mod = parseInt(cups16, 10) % 529,
quotient = Math.floor(cup16Mod / 23),
remainder = cup16Mod % 23;
ret = (control === letters[quotient] + letters[remainder]);
return ret;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.