Last active
February 17, 2017 13:14
-
-
Save DiegoLopesLima/014b1c3194ad68b23f16e7d84630a24b to your computer and use it in GitHub Desktop.
Return true if param value is a valid BRA Individual Registration (CPF).
This file contains 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 isValidBRAIR(value) { | |
value = String(value).replace(/[^\d]/g, ''); | |
if (value.length === 11 && !/^(\d)\1+$/.test(value)) { | |
for (var from = 10, to = 2, sum = 0, index = -1; from > (to - 1); from--) | |
sum += value[++index] * from; | |
if (((sum * 10) % 11) == value[9]) { | |
for (var from = 11, to = 2, sum = 0, index = -1; from > (to - 1); from--) | |
sum += value[++index] * from; | |
return ((sum * 10) % 11) == value[10]; | |
} else return false; | |
} else return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment