Last active
April 19, 2022 18:40
-
-
Save periplox/c745d471f39ca59c81b51b4ac0bcee4b to your computer and use it in GitHub Desktop.
Función de JS para validación de CUIT/CUIL (Argentina)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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