Author: Ronald Buster
How to check if a social security number is valid ??
note : only tested on the dutch social security numbers
Answer:
1
2 function CheckFiscaalNumber(Value: string): boolean;
3 var
4 n1, n2, n3, n4, n5, n6, n7, n8, n9: integer;
5 s1, s2, s3, s4, s5, s6, s7, s8: integer;
6 totaal, rest: integer;
7 begin
8 if StrToInt(Value) > 10000000 then
9 begin
10 if Length(Value) >= 8 then
11 begin
12
13 if Length(Value) = 8 then
14 begin
15 Value := '0' + Value;
16 end;
17
18 n1 := StrToInt(copy(Value, 1, 1));
19 n2 := StrToInt(copy(Value, 2, 1));
20 n3 := StrToInt(copy(Value, 3, 1));
21 n4 := StrToInt(copy(Value, 4, 1));
22 n5 := StrToInt(copy(Value, 5, 1));
23 n6 := StrToInt(copy(Value, 6, 1));
24 n7 := StrToInt(copy(Value, 7, 1));
25 n8 := StrToInt(copy(Value, 8, 1));
26 n9 := StrToInt(copy(Value, 9, 1));
27
28 s1 := n1 * 9;
29 s2 := n2 * 8;
30 s3 := n3 * 7;
31 s4 := n4 * 6;
32 s5 := n5 * 5;
33 s6 := n6 * 4;
34 s7 := n7 * 3;
35 s8 := n8 * 2;
36
37 totaal := s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8;
38 rest := totaal mod 11;
39
40 if rest <> n9 then
41 begin
42 Result := False;
43 end
44 else
45 begin
46 Result := True;
47 end;
48 end
49 else
50 begin
51 Result := False;
52 end;
53
54 end
55 else
56 begin
57 Result := False;
58 end;
59
60 end;
|