Ver Mensaje Individual
  #3  
Antiguo 13-05-2008
Troffed Troffed is offline
Miembro
 
Registrado: mar 2004
Posts: 51
Reputación: 21
Troffed Va por buen camino
gerardus, me permito "repostear" tu mensaje utilizando las etiquetas CODE

Código:
const
Tabla_AlfaDigitos: array['A'..'Z'] of integer = (10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35);

// function Clean_IBAN
// Devuelve un numero de cuenta IBAN "limpio", sin 'IBAN', ni espacios, ni guiones...

function Clean_IBAN(Cuenta: string): string;
var
  i: integer;
begin
  result := '';
  // Pasar a mayusculas i eliminar espacios
  Cuenta := UpperCase(Trim(Cuenta));
  // Eliminar posible 'IBAN'
  if Copy(Cuenta, 1, 4) = 'IBAN' then
    Delete(Cuenta, 1, 4);
  // Pasar solo caracteres alfanumericos
  for i := 1 to length(Cuenta) do
   if Cuenta in ['a'..'z', 'A'..'Z', '0'..'9'] then
    result := result + Cuenta;
end;

// function check_iban
// devuelve true si el numero de cuenta que le pasamos es un numero de cuenta IBAN valido
function Check_IBAN(Cuenta: string): Boolean;
var
  s, s2, s3: string;
  i: integer;
  AInt64: Int64;
  AMod: Integer;
  APos: Integer;
begin
  if Trim(Cuenta)='' then
    result := false
  else
  begin
    try
      // Pulir Cuenta.
      Cuenta := Clean_IBAN(Cuenta);
      // Mover 4 primeros digitos al final
      s := Copy(Cuenta, 5, length(Cuenta) - 4) + Copy(Cuenta, 1, 4);
      // Convertir letras a digitos
      s2 := '';
      for i := 1 to length(s) do
      begin
        if s in ['A'..'Z'] then
          s2 := s2 + FormatFloat('00', Tabla_AlfaDigitos[s])
        else
          s2 := s2 + s;
      end;
      // Calcular resultado del numero mod 97.
      // Bucle calculando mods
      while length(s2) > 18 do
      begin
        s3 := Copy(s2, 1, 18);
        Amod := StrToInt64(s3) mod 97;
        s2 := IntToStr(AMod) + Copy(s2, 19, Length(s2) - 16);
      end;
      result := StrToInt64(s2) mod 97 = 1;
    except
      result := false;
    end;
  end;
end;
Espero que no te importe.
Responder Con Cita