Digito verificador do PIS [RESOLVIDO]

2 respostas
esqueleto

Pessoal estou precisando do codigo em java que faz a verficação do PIS mas se tiver só as instruções de como é feito o calculo tbm vale. Obrigado pela atenção.

Esqueleto.

“Eu te pego He Man NHEM!!! NHEM!!! NHEM!!!”

2 Respostas

dsiviotti

Esse pedaço de código deve ser suficiente:

...
    /** PIS/PASEP Digit Count*/
    public static final int DIGIT_COUNT = 11;
    /**PIS/PASEP Validation.<P>
     * Returns true if valid or false if invalid.
     * @param pisOrPasep The PIS/PASEP to validate.
     * @return true if valid or false if invalid.
     */
    public static boolean isValid(String pisOrPasep){
        if (pisOrPasep == null) return false;
        String n = pisOrPasep.replaceAll("[^0-9]*","");
        if (n.length() != DIGIT_COUNT) return false;
        int i;          // just count 
        int digit;      // A number digit
        int coeficient; // A coeficient  
        int sum;        // The sum of (Digit * Coeficient)
        int foundDv;    // The found Dv (Chek Digit)
        int dv = Integer.parseInt(String.valueOf(n.charAt(n.length()-1)));      
        sum = 0;
        coeficient = 2;
        for (i = n.length() - 2; i >= 0 ; i--){
            digit = Integer.parseInt(String.valueOf(n.charAt(i)));               
            sum += digit * coeficient;
            coeficient ++;
            if (coeficient > 9) coeficient = 2;                
        }                
        foundDv = 11 - sum % 11;
        if (foundDv >= 10) foundDv = 0;        
        return dv == foundDv;
    }
   ...

Existe um projeto para fazer essas e outras validações em java. Se puder participe. Você pode baixar a classe inteira em:
https://brazilutils.dev.java.net/

esqueleto

Valeu vou participar

Criado 12 de julho de 2005
Ultima resposta 12 de jul. de 2005
Respostas 2
Participantes 2