Ver Mensaje Individual
  #2  
Antiguo 13-05-2008
gerardus gerardus is offline
Miembro
 
Registrado: dic 2007
Posts: 43
Reputación: 0
gerardus Va por buen camino
Gracias. Añado una rutina que verifica que un numero de cuenta sea valido.

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[i] in ['a'..'z', 'A'..'Z', '0'..'9'] then
result := result + Cuenta[i];
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[i] in ['A'..'Z'] then
s2 := s2 + FormatFloat('00', Tabla_AlfaDigitos[s[i]])
else
s2 := s2 + s[i];
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;
Responder Con Cita