whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

54 Visitors Online


 
...check a String for a Valid Email Address?
Autor: Ollo Heß
[ Print tip ]  

Tip Rating (25):  
     


function MailURLMayBeInvalid(const s: string): Boolean;
var
  
i: Integer;
  c: string;
begin // ' ', ä, ö, ü, ß, [, ], (, ), : in EMail-Address
  
Result := (Trim(s) = '') or (Pos(' ', AnsiLowerCase(s)) > 0) or
    
(Pos('ä', AnsiLowerCase(s)) > 0) or (Pos('ö', AnsiLowerCase(s)) > 0) or
    
(Pos('ü', AnsiLowerCase(s)) > 0) or (Pos('ß', AnsiLowerCase(s)) > 0) or
    
(Pos('[', AnsiLowerCase(s)) > 0) or (Pos(']', AnsiLowerCase(s)) > 0) or
    
(Pos('(', AnsiLowerCase(s)) > 0) or (Pos(')', AnsiLowerCase(s)) > 0) or
    
(Pos(':', AnsiLowerCase(s)) > 0);
  if Result then Exit; // @ not in EMail-Address;
  
i      := Pos('@', s);
  Result := (i = 0) or (i = 1) or (i = Length(s));
  if Result then Exit;
  Result := (Pos('@', Copy(s, i + 1, Length(s) - 1)) > 0);
  if Result then Exit; // Domain <= 1
  
c      := Copy(s, i + 1, Length(s));
  Result := Length(c) <= 1;
  if Result then Exit;
  i      := Pos('.', c);
  Result := (i = 0) or (i = 1) or (i = Length(c));
end;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners