Skip to content

Instantly share code, notes, and snippets.

@evikza
Last active September 14, 2021 02:50
Show Gist options
  • Select an option

  • Save evikza/5102a26a15efc0fd53ea711639e9ca13 to your computer and use it in GitHub Desktop.

Select an option

Save evikza/5102a26a15efc0fd53ea711639e9ca13 to your computer and use it in GitHub Desktop.
Проверка ОГРН и ОГРНИП
function isPrimaryStateRegistrationNumber($number) {
let n = $number.length == 13 ? 11 : $number.length == 15 ? 13 : 0,
j = $number.slice(0, -1),
v = j / n,
g = v.toString().replace(/\..*/gm, '') * n,
f = (j - g).toString(),
k = f > 9 ? f.slice(-1) : f,
t = k == $number.toString().slice(-1);
return t;
}
console.log(isPrimaryStateRegistrationNumber('1027700132195'));
// -> true
console.log(isPrimaryStateRegistrationNumber('5220710132791'));
// -> false
console.log(isPrimaryStateRegistrationNumber('313132804400022'));
// -> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment