-
Notifications
You must be signed in to change notification settings - Fork 1
/
IsURL.pas
64 lines (64 loc) · 1.92 KB
/
IsURL.pas
1
2
3
4
5
6
7
8
9
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function IsUrl(S: string): Boolean;
//
// Testa se a String é uma url ou não
//
const
BADCHARS = ';*<>{}[]|\()^!';
var
p, x, c, count, i: Integer;
begin
Result := False;
if (Length(S) > 5) and (S[Length(S)] <> '.') and (Pos(S, '..') = 0) then
begin
for i := Length(BADCHARS) downto 1 do
begin
if Pos(BADCHARS[i], S) > 0 then
begin
exit;
end;
end;
for i := 1 to Length(S) do
begin
if (Ord(S[i]) < 33) or (Ord(S[i]) > 126) then
begin
exit;
end;
end;
if ((Pos('www.',LowerCase(S)) = 1) and (Pos('.', Copy(S, 5, Length(s))) > 0) and (Length(S) > 7)) or ((Pos('news:', LowerCase(S)) = 1) and (Length(S) > 7) and (Pos('.', Copy(S, 5, Length(S))) > 0)) then
begin
end
else if ((Pos('mailto:', LowerCase(S)) = 1) and (Length(S) > 12) and (Pos('@', S) > 8) and (Pos('.', S) > 10) and (Pos('.', S) > (Pos('@', S) +1))) or ((Length(S) > 6) and (Pos('@', S) > 1) and (Pos('.', S) > 4) and (Pos('.', S) > (Pos('@', S) +1))) then
begin
Result := True;
Exit;
end
else if ((Pos('http://', LowerCase(S)) = 1) and (Length(S) > 10) and (Pos('.', S) > 8)) or ((Pos('ftp://', LowerCase(S)) = 1) and (Length(S) > 9) and (Pos('.', S) > 7)) then
begin
Result := True;
Exit;
end
else
begin
Result := True;
end;
for Count := 1 to 4 do
begin
p := Pos('.',S) - 1;
if p < 0 then
begin
p := Length(S);
end;
Val(Copy(S, 1, p), x, c);
if ((c <> 0) or (x < 0) or (x > 255) or (p>3)) then
begin
Result := False;
Break;
end;
Delete(S, 1, p + 1);
end;
if (S <> '') then
begin
Result := False;
end;
end;
end;