Lo he resuelto así.
Pero ojo!!!! No tengo suficientes CIF's y NIF's para hacer la comprobación, por lo que puede ser que falle en algún caso.
Es unha modificación sobre unas funciones que no recuerdo de donde las saqué, quizás de trucomania.
Código Delphi
[-]
function TDatos.EsCif(Cif : String) : Boolean;
var
Suma, Control : Integer;
n : Byte;
begin
Result := False;
Cif := UpperCase(Trim(Cif));
Cif := CadCambioCar(Cif,'-','');
Cif := CadCambioCar(Cif,'/','');
if Length(Cif) = 9 then
begin
if (pos(Cif[1],'0123456789'))>0 then
Result := EsNif(Cif)
else
begin
if (Pos(Cif[1], 'ABCDEFGHPQSKLMXYZJUVWR') = 0) then
Result := False
else
if (Pos(Cif[1], 'XYZ') = 1) then
Result := EsNif('0'+Copy(Cif,2,8))
else
begin
Suma:= StrToInt(Cif[3])+StrToInt(Cif[5])+StrToInt(Cif[7]);
for n := 1 to 4 do
Suma := Suma +
((2*StrToInt(Cif[2*n])) mod 10)+((2*StrToInt(Cif[2*n])) div 10);
Control := 10 - (Suma mod 10);
if Pos(Cif[1],'PSQ')<>0 then
Result := (Cif[9] = Chr(64+Control))
else
begin
if Control = 10 then
Control := 0;
Result:= ( StrToInt(Cif[9]) = Control);
end;
end;
end;
end;
end;
function TDatos.EsNif(Cif:String): Boolean;
var a:string;
Dni:String;
Letra:String;
begin
Dni:=copy(cif,1,8);
a:=Copy('TRWAGMYFPDXBNJZSQVHLCKET',StrToInt( Dni ) mod 23 + 1, 1 );
Letra:=Copy(cif,9,1);
if a = letra then
result:=True
else
result:=False;
end;