[Lazarus] Checking characters in a string
silvioprog
silvioprog at gmail.com
Wed Mar 12 19:19:29 CET 2014
Oops...
2014-03-12 15:08 GMT-03:00 silvioprog <silvioprog at gmail.com>:
[...]
> // new
> function ValidPassword(const S: string): Boolean;
> var
> P: PChar;
> F: Boolean;
> L: Boolean = False;
> U: Boolean = False;
> N: Boolean = False;
> begin
> P := PChar(S);
> while P^ <> #0 do
> begin
> case P^ of
> #48..#57: N := True;
> #65..#90: U := True;
> #97..#122: L := True;
> else
> F := P^ = #195;
> if F then
> case P[1] of
> #128..#159: U := True;
> #160..#191: L := True;
> end;
> end;
> Inc(P);
> end;
> Result := L and U and N;
> end;
>
Correct function is:
function ValidPassword(const S: string): Boolean;
var
P: PChar;
L: Boolean = False;
U: Boolean = False;
N: Boolean = False;
begin
P := PChar(S);
while P^ <> #0 do
begin
case P^ of
#48..#57: N := True;
#65..#90: U := True;
#97..#122: L := True;
else
if P^ = #195 then
case P[1] of
#128..#159: U := True;
#160..#191: L := True;
end;
end;
Inc(P);
end;
Result := L and U and N;
end;
--
Silvio Clécio
My public projects - github.com/silvioprog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20140312/02ed1775/attachment-0003.html>
More information about the Lazarus
mailing list