fcl-md: func IsValidEmail is too weak
markdown.utils.pas
function IsValidEmail(const S : String) : boolean;
type
TState = (sNeutral,sUser,sHost,sDomain);
var
lState : TState;
c : char;
begin
Result:=False;
if s.CountChar('@') <> 1 then
Exit;
lState:=sNeutral;
for c in s do
Case lState of
sNeutral:
if c='@' then
Exit
else
lState:=sUser;
sUser:
if c='@' then
lState:=sHost;
else
if c='.' then
lState:=sDomain
else if c='+' then
Exit;
end;
Result:=lState=sDomain;
end;
- func detects empty username and returns False. but it don't detect empty hostname nor empty domain. these return True:
IsValidEmail('a@.a')
IsValidEmail('a@a.')
-
domain-name must have at least 2 wordchars. currently, I repeat, minimal count is 0.
-
need to detect that hostname/domain have only wordchars, not any chars.
-
for username - some punctuations are allowed too. this must be checked. supported char-set for username can be asked from good AI.
note: pls don't use RegEx for this func if you work on it, it will by slower by 1-2 orders.
Edited by Alexey Torgashin