Skip to content

Instantly share code, notes, and snippets.

@DiegoLopesLima
Last active February 17, 2017 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DiegoLopesLima/014b1c3194ad68b23f16e7d84630a24b to your computer and use it in GitHub Desktop.
Save DiegoLopesLima/014b1c3194ad68b23f16e7d84630a24b to your computer and use it in GitHub Desktop.
Return true if param value is a valid BRA Individual Registration (CPF).
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