Posted By

alejandrosuch on 04/21/10


Tagged

ccc validador


Versions (?)

Validar CCC


 / Published in: Java
 

  1. import java.io.Serializable;
  2.  
  3. public class ValidarCCC implements Serializable
  4. {
  5. private static final long serialVersionUID = 1L;
  6.  
  7. public static boolean validarCCC (String ccc)
  8. {
  9. try{
  10. String banco = ccc.substring(0,4);
  11. String sucursal = ccc.substring(4,8 );
  12. String dc = ccc.substring(8, 10);
  13. String cccCuenta = ccc.substring(10);
  14. Integer.parseInt(banco);
  15. Integer.parseInt(sucursal);
  16. Integer.parseInt(dc);
  17. Integer.parseInt(cccCuenta);
  18. String bancoSucursal = "00"+banco+sucursal;
  19.  
  20. if(!obtenerDC(bancoSucursal).equalsIgnoreCase(dc.substring(0, 1)) ||
  21. !obtenerDC(cccCuenta).equalsIgnoreCase(dc.substring(1, 2)) )
  22. return false;
  23. }catch(Exception e){
  24. return false;
  25. }
  26. return true;
  27. }
  28.  
  29. public static String obtenerDC(String valor){
  30. int[] valores = new int[]{1, 2, 4, 8, 5, 10, 9, 7, 3, 6};
  31. int control = 0;
  32. for (int i=0; i<=9; i++)
  33. control += Integer.parseInt(String.valueOf(valor.charAt(i))) * valores[i];
  34. control = 11 - (control % 11);
  35. if (control == 11) control = 0;
  36. else if (control == 10) control = 1;
  37. return String.valueOf(control);
  38. }
  39. }

Report this snippet  

You need to login to post a comment.