Skip to content

Instantly share code, notes, and snippets.

@periplox
Last active April 19, 2022 18:40
Show Gist options
  • Select an option

  • Save periplox/c745d471f39ca59c81b51b4ac0bcee4b to your computer and use it in GitHub Desktop.

Select an option

Save periplox/c745d471f39ca59c81b51b4ac0bcee4b to your computer and use it in GitHub Desktop.
Función de JS para validación de CUIT/CUIL (Argentina)
function validateCuitCuil(num) {
const multipliers = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1];
const validPrefixes = [20, 23, 24, 27, 30, 33, 34];
const digits = num.toString().split('');
const prefix = parseInt(digits[0]+digits[1]);
if (digits.length != 11 || !validPrefixes.includes(prefix)) return false;
const reduction = digits.reduce((carry, value, index) => {
return carry + (value * multipliers[index])
}, 0);
const result = reduction / 11;
return result == Math.floor(result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment