Como tinha dito em post anterior, fui ao INSS e peguei os algorítmos para validação de CEI e PIS/PASEP.
Segue o código C# para validação do PIS:
// Validar PIS/PASEP
public bool validaPIS( string parametro )
{
bool retorno = false;
if( parametro.Length == 14 ){
if( Regex.IsMatch( parametro, @"[0-9]{3}.[0-9]{5}.[0-9]{2}-[0-9]{1}" ) ){
string _pis = parametro.Replace(".","");
_pis = _pis.Replace("-","");
string digitoVerificador = _pis.Substring(10,1);
int tot = ( Convert.ToInt32( _pis.Substring(0,1) ) * 3);
tot += ( Convert.ToInt32( _pis.Substring(1,1) ) * 2);
tot += ( Convert.ToInt32( _pis.Substring(2,1) ) * 9);
tot += ( Convert.ToInt32( _pis.Substring(3,1) ) * 8);
tot += ( Convert.ToInt32( _pis.Substring(4,1) ) * 7);
tot += ( Convert.ToInt32( _pis.Substring(5,1) ) * 6);
tot += ( Convert.ToInt32( _pis.Substring(6,1) ) * 5);
tot += ( Convert.ToInt32( _pis.Substring(7,1) ) * 4);
tot += ( Convert.ToInt32( _pis.Substring(8,1) ) * 3);
tot += ( Convert.ToInt32( _pis.Substring(9,1) ) * 2);
string dv = (11 - (tot % 11 )).ToString();
if( dv == digitoVerificador ){
retorno = true;
}
}
}
return retorno;
}
Bom proveito!
Dúvidas, críticas ou sugestões estamos ae! heheh
[]'s