Extracting And Validating Email Addresses (Views: 28)
Problem/Question/Abstract: This code example introduces a new way to validate Email Addresses with domain name (TLD) validation !! Answer: Code #1 function IsEMail(EMail: string): Boolean; var s: string; ETpos: Integer; begin ETpos := pos('@', EMail); if ETpos > 1 then begin s := copy(EMail, ETpos + 1, Length(EMail)); if (pos('.', s) > 1) and (pos('.', s) < length(s)) then Result := true else Result := false; end else Result := false; end; procedure TForm1.Button1Click(Sender: TObject); begin if isemail(Edit1.Text) then begin ShowMessage('eMail-Adresse!'); end; end; Code #2 MaxDomains = 174; DomainList: array[0..MaxDomains] of string[3] = ( 'AD', 'AE', 'AG', 'AI', 'AM', 'AR', 'AS', 'AT', 'AU', 'AW', 'AZ', 'BA', 'BE', 'BF', 'BG', 'BH', 'BM', 'BN', 'BO', 'BR', 'BS', 'BW', 'BY', 'BZ', 'CA', 'CC', 'CH', 'CI', 'CK', 'CL', 'CN', 'CO', 'COM', 'CR', 'CU', 'CY', 'CZ', 'DE', 'DK', 'DM', 'DO', 'DZ', 'EC', 'EDU', 'EE', 'EG', 'ES', 'ET', 'FI', 'FJ', 'FK', 'FM', 'FO', 'FR', 'GB', 'GE', 'GF', 'GH', 'GI', 'GL', 'GOV', 'GR', 'GT', 'GU', 'GW', 'GY', 'HK', 'HN', 'HR', 'HU', 'ID', 'IE', 'IL', 'IN', 'INT', 'IO', 'IR', 'IS', 'IT', 'JM', 'JO', 'JP', 'KE', 'KG', 'KH', 'KI', 'KM', 'KR', 'KW', 'KY', 'KZ', 'LB', 'LI', 'LK', 'LT', 'LU', 'LV', 'MA', 'MC', 'MD', 'MIL', 'MK', 'MN', 'MO', 'MR', 'MT', 'MU', 'MV', 'MX', 'MY', 'MZ', 'NA', 'NC', 'NE', 'NET', 'NF', 'NG', 'NI', 'NL', 'NO', 'NP', 'NU', 'NZ', 'OM', 'ORG', 'PA', 'PE', 'PF', 'PG', 'PH', 'PK', 'PL', 'PR', 'PT', 'PY', 'QA', 'RO', 'RU', 'SA', 'SE', 'SG', 'SI', 'SK', 'SL', 'SM', 'SN', 'ST', 'SU', 'SV', 'SZ', 'TC', 'TF', 'TG', 'TH', 'TM', 'TO', 'TR', 'TT', 'TW', 'TZ', 'UA', 'UG', 'UK', 'US', 'UY', 'UZ', 'VA', 'VE', 'VI', 'VN', 'YE', 'YU', 'ZA', 'ZM', 'ZW'); function InDomainList(email: string): boolean; var tel: word; st: string; begin tel := length(email); while (tel > 0) and (email[tel] <> '.') do dec(tel); st := copy(email, tel + 1, length(email)); for tel := 0 to maxdomains do if st = DomainList[tel] then begin InDomainList := true; inc(hittable[tel]); exit; end; InDomainList := false; end; Have Fun !!! |