0
\$\begingroup\$

I have created this function for Delphi 10.1 Berlin to validate an email address entered by the user:

function IsValidEmailAddress(const AString: string): Boolean;
begin
  Result := System.RegularExpressions.TRegEx.IsMatch(AString, '^[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}\Z$', [roIgnoreCase]);
end;

Usage:

if not IsValidEmailAddress(Trim(edtEmail.Text)) then
  ...

Are there any valid email addresses which could be detected as invalid with this function?

\$\endgroup\$
3
1
\$\begingroup\$

I think there are some emails that will be invalid with your function. Like this: thisissanPrivateMail@example.wolterskluwer (when a domain name is more than 6 symbols).

About email address length, according to https://www.lifewire.com/is-email-address-length-limited-1171110 RFC 2821 can be summarized as:

limit the local part of the email address to 64 or fewer characters and limit the total email address to 254 characters

You can check your regular expression online, for example, here: https://regexr.com/ or https://regex101.com/

\$\endgroup\$
2
  • \$\begingroup\$ Hey, welcome to Code Review! Since links can rot, you should include the relevant parts of the linked page in your answer to conserve it for posterity. In this case just include the length requirements stated there. Off-topic, who calls the @ sign "ampersand" (except the person who wrote that article)? \$\endgroup\$ – Graipher Sep 28 '18 at 12:14
  • \$\begingroup\$ Thanks, @Graipher. And about "ampersand", it's a really good question. \$\endgroup\$ – Kate Lobatenko Sep 28 '18 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.