validarPIS static method

bool validarPIS(
  1. dynamic numero
)

Valida um nĂºmero de PIS.

Implementation

static bool validarPIS(dynamic numero) {
  string text = "$numero";
  if (text.isNotValid()) {
    return false;
  }

  text = text.replaceAll(RegExp(r'[^0-9]'), '');

  if (text.length != 11) {
    return false;
  }

  var count = text[0];
  if (text.split('').where((w) => w == count).length == text.length) {
    return false;
  }

  var multiplicador = [3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
  int soma = 0;
  int resto;

  for (var i = 0; i < 10; i++) {
    soma += int.parse(text[i]) * multiplicador[i];
  }

  resto = soma % 11;

  resto = resto < 2 ? 0 : 11 - resto;

  return text.toLowerCase().endsWith(resto.toString().toLowerCase());
}