[{"data":1,"prerenderedAt":63},["ShallowReactive",2],{"content:en:blog\u002Femail-validation-regex":3},{"path":4,"locale":5,"section":6,"title":7,"description":8,"html":9,"headings":10,"faq":40,"updated":59,"order":60,"words":61,"meta":62},"blog\u002Femail-validation-regex","en","blog","Email validation regex: what a pattern can check, and what it cannot","What RFC 5321, RFC 5322 and RFC 6531 allow in an email address, a practical regex for forms, the cases it misses, and what to run after it.","\u003Cp>A regular expression checks that a string looks like an email address. It cannot check that the address works. Use a short pattern in the form so a user gets immediate feedback on obvious mistakes, and then run the checks that need DNS and the mail server. Everything in this article follows from that split: syntax is cheap and local, deliverability is neither.\u003C\u002Fp>\n\u003Ch2 id=\"what-the-standards-say-an-address-is\">\u003Ca class=\"heading-link\" href=\"#what-the-standards-say-an-address-is\">\u003Cspan>What the standards say an address is\u003C\u002Fspan>\u003C\u002Fa>\u003C\u002Fh2>\n\u003Cp>Three documents matter.\u003C\u002Fp>\n\u003Cul>\n\u003Cli>\u003Cstrong>RFC 5321\u003C\u002Fstrong> defines SMTP, the protocol that moves mail. It sets limits: the local part, before the \u003Ccode>@\u003C\u002Fcode>, can have at most 64 octets, and the domain at most 255. The forward path, which wraps the address in angle brackets, is limited to 256 octets, so a usable address is about 254 characters.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>RFC 5322\u003C\u002Fstrong> defines the format of a message and the grammar of an address, called \u003Ccode>addr-spec\u003C\u002Fcode>. The local part is either a \u003Ccode>dot-atom\u003C\u002Fcode> (letters, digits and a set of symbols, with dots between atoms) or a quoted string. The domain is a dot-atom or a bracketed address literal.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>RFC 6531\u003C\u002Fstrong> extends SMTP so that addresses can contain UTF-8 in the local part and an internationalized domain. A server that supports it advertises the \u003Ccode>SMTPUTF8\u003C\u002Fcode> extension.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Cp>Domain labels follow DNS rules from RFC 1035: each label is at most 63 octets. Those limits, and not the grammar, are what a regex can check cheaply.\u003C\u002Fp>\n\u003Ch3 id=\"why-the-full-grammar-is-a-poor-regex\">\u003Ca class=\"heading-link\" href=\"#why-the-full-grammar-is-a-poor-regex\">\u003Cspan>Why the full grammar is a poor regex\u003C\u002Fspan>\u003C\u002Fa>\u003C\u002Fh3>\n\u003Cp>The RFC 5322 grammar also allows comments in parentheses, folding whitespace and a set of obsolete forms kept for compatibility. A pattern that matched all of it would run to thousands of characters and still say nothing about delivery. The goal for a form is the opposite: accept what real people have, reject what they mistype.\u003C\u002Fp>\n\u003Ch2 id=\"a-practical-pattern\">\u003Ca class=\"heading-link\" href=\"#a-practical-pattern\">\u003Cspan>A practical pattern\u003C\u002Fspan>\u003C\u002Fa>\u003C\u002Fh2>\n\u003Cp>The HTML Living Standard defines what a browser treats as a valid email address for \u003Ccode>input type=email\u003C\u002Fcode>, and it says outright that its definition is a willful violation of RFC 5322, chosen to be simpler and more practical. It is a good default for forms:\u003C\u002Fp>\n\u003Cdiv class=\"code-block\" data-code-block>\u003Cdiv class=\"code-head\">\u003Cspan class=\"code-label\">javascript\u003C\u002Fspan>\u003C\u002Fdiv>\u003Cpre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\">\u003Ccode class=\"language-javascript\">\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">const\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> emailPattern\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> =\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">  \u002F\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">^\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">[a-zA-Z0-9.!#$%&#x26;'*+\u002F=?^_`{|}~-]\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">+\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#DBEDFF\">@\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">[a-zA-Z0-9]\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#DBEDFF\">(?:\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">[a-zA-Z0-9-]\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">{0,61}\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">[a-zA-Z0-9]\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#DBEDFF\">)\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">?\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#DBEDFF\">(?:\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#22863A;--shiki-light-font-weight:bold;--shiki-dark:#85E89D;--shiki-dark-font-weight:bold\">\\.\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">[a-zA-Z0-9]\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#DBEDFF\">(?:\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">[a-zA-Z0-9-]\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">{0,61}\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">[a-zA-Z0-9]\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#DBEDFF\">)\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">?\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#DBEDFF\">)\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">*$\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\u002F\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">export \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">function\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\"> looksLikeEmail\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">value\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">) {\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">  const\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> email\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> =\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> value.\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">trim\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">()\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">  return\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> email.\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">length\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> &#x3C;=\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> 254\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> &#x26;&#x26;\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> emailPattern.\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">test\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(email)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">}\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fcode>\u003C\u002Fpre>\n\u003C\u002Fdiv>\n\u003Cp>It limits each domain label to 63 characters, as DNS does, and it allows the symbols RFC 5322 permits in an unquoted local part. We ran it against a set of inputs to see where it agrees with the standard and where it does not.\u003C\u002Fp>\n\u003Cdiv class=\"table-wrap\">\u003Ctable>\n\u003Cthead>\n\u003Ctr>\n\u003Cth>Input\u003C\u002Fth>\n\u003Cth>Pattern says\u003C\u002Fth>\n\u003Cth>Comment\u003C\u002Fth>\n\u003C\u002Ftr>\n\u003C\u002Fthead>\n\u003Ctbody>\n\u003Ctr>\n\u003Ctd>\u003Ccode>jane@example.com\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>Accepts\u003C\u002Ftd>\n\u003Ctd>Fine\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>\u003Ccode>jane+shop@example.com\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>Accepts\u003C\u002Ftd>\n\u003Ctd>Subaddressing is legitimate\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>\u003Ccode>jane@gmial.com\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>Accepts\u003C\u002Ftd>\n\u003Ctd>A typo: syntax is fine, the domain is wrong\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>\u003Ccode>jane@localhost\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>Accepts\u003C\u002Ftd>\n\u003Ctd>A domain with no dot; fine for the standard, rarely what a signup wants\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>\u003Ccode>a@b\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>Accepts\u003C\u002Ftd>\n\u003Ctd>Same: one-label domain\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>\u003Ccode>jane..doe@example.com\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>Accepts\u003C\u002Ftd>\n\u003Ctd>Not allowed by the dot-atom rule in RFC 5322\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>\u003Ccode>.jane@example.com\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>Accepts\u003C\u002Ftd>\n\u003Ctd>Same: a leading dot\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>\u003Ccode>jane@example..com\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>Rejects\u003C\u002Ftd>\n\u003Ctd>An empty label\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>\u003Ccode>jane@-example.com\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>Rejects\u003C\u002Ftd>\n\u003Ctd>A label cannot start with a hyphen\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>\u003Ccode>&quot;jane doe&quot;@example.com\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>Rejects\u003C\u002Ftd>\n\u003Ctd>Legal per RFC 5322, but a quoted local part is rare\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>\u003Ccode>jane@[192.0.2.1]\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>Rejects\u003C\u002Ftd>\n\u003Ctd>An address literal, legal and almost never wanted\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>\u003Ccode>用户@例子.广告\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>Rejects\u003C\u002Ftd>\n\u003Ctd>A UTF-8 address under RFC 6531; see below\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>\u003Ccode>jane@example.com.\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>Rejects\u003C\u002Ftd>\n\u003Ctd>A trailing dot\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003C\u002Ftbody>\n\u003C\u002Ftable>\u003C\u002Fdiv>\n\u003Cp>The pattern is lenient on the dots in the local part and strict on the domain. That is the pragmatic trade, and it shows the point of the next section: syntax cannot settle what is deliverable.\u003C\u002Fp>\n\u003Ch2 id=\"what-a-regex-cannot-know\">\u003Ca class=\"heading-link\" href=\"#what-a-regex-cannot-know\">\u003Cspan>What a regex cannot know\u003C\u002Fspan>\u003C\u002Fa>\u003C\u002Fh2>\n\u003Cul>\n\u003Cli>\u003Cstrong>Whether the domain exists.\u003C\u002Fstrong> \u003Ccode>jane@this-domain-does-not-exist.example\u003C\u002Fcode> is well formed. A DNS lookup for MX records is what shows that a domain can receive mail.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Whether the mailbox exists.\u003C\u002Fstrong> Only the recipient's mail server knows. A verifier asks it, with the \u003Ccode>RCPT TO\u003C\u002Fcode> command, and never sends a message.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Whether the user mistyped.\u003C\u002Fstrong> \u003Ccode>gmial.com\u003C\u002Fcode> is syntactically perfect. A suggestion engine that compares the domain with common ones is what catches it.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Whether the address is disposable or a role.\u003C\u002Fstrong> \u003Ccode>info@\u003C\u002Fcode> and a throwaway inbox match every pattern.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Whether it is the user's own.\u003C\u002Fstrong> Only a confirmation email proves that.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Cp>Each of those is a different check. \u003Ca href=\"\u002Fblog\u002Fhow-to-verify-an-email-address\">How to verify an email address\u003C\u002Fa> walks through them in order.\u003C\u002Fp>\n\u003Ch2 id=\"internationalized-addresses\">\u003Ca class=\"heading-link\" href=\"#internationalized-addresses\">\u003Cspan>Internationalized addresses\u003C\u002Fspan>\u003C\u002Fa>\u003C\u002Fh2>\n\u003Cp>RFC 6531 lets an address carry non-ASCII characters in the local part, and the domain can be written in its own script. Support is growing but uneven, and the pattern above rejects those addresses. Decide on purpose: if your market has such users, loosen the local part to accept any non-whitespace character other than \u003Ccode>@\u003C\u002Fcode>, and let the later checks decide. If it does not, a clear message is better than a silent failure. Whichever way you go, test it. Do not discover your behaviour from a support ticket.\u003C\u002Fp>\n\u003Ch2 id=\"case-whitespace-and-the-plus-sign\">\u003Ca class=\"heading-link\" href=\"#case-whitespace-and-the-plus-sign\">\u003Cspan>Case, whitespace and the plus sign\u003C\u002Fspan>\u003C\u002Fa>\u003C\u002Fh2>\n\u003Cul>\n\u003Cli>\u003Cstrong>Trim whitespace.\u003C\u002Fstrong> Paste often brings a trailing space. Trim before you test and before you store.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Keep the case you were given.\u003C\u002Fstrong> Domains are case-insensitive. The local part is, by RFC 5321, case-sensitive in theory and treated as case-insensitive by almost every provider. Lowercase for comparison, and store the original too.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Never strip the plus tag.\u003C\u002Fstrong> Providers use it for subaddressing. Removing it changes the address.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Do not collapse dots.\u003C\u002Fstrong> Some providers ignore dots in a local part. Many do not. You cannot know which.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Ch2 id=\"then-run-the-checks-that-matter\">\u003Ca class=\"heading-link\" href=\"#then-run-the-checks-that-matter\">\u003Cspan>Then run the checks that matter\u003C\u002Fspan>\u003C\u002Fa>\u003C\u002Fh2>\n\u003Cp>Syntax is the first of several checks, and the Qelka email API runs them all. \u003Ccode>checks.syntax\u003C\u002Fcode> is the pattern-level result, and the rest of the response covers what a regex cannot:\u003C\u002Fp>\n\u003Cdiv class=\"code-block\" data-code-block>\u003Cdiv class=\"code-head\">\u003Cspan class=\"code-label\">bash\u003C\u002Fspan>\u003C\u002Fdiv>\u003Cpre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\">\u003Ccode class=\"language-bash\">\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">curl\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> https:\u002F\u002Fapi.qelka.com\u002Fv1\u002Femail\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> \\\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">  -H\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> \"Authorization: Bearer \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">$API_KEY\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> \\\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">  -H\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> \"Content-Type: application\u002Fjson\"\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> \\\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">  -d\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> '{\"email\": \"jane@gmial.com\", \"mode\": \"fast\"}'\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fcode>\u003C\u002Fpre>\n\u003C\u002Fdiv>\n\u003Cp>The response carries \u003Ccode>status\u003C\u002Fcode>, a \u003Ccode>reason\u003C\u002Fcode>, a \u003Ccode>did_you_mean\u003C\u002Fcode> suggestion such as \u003Ccode>jane@gmail.com\u003C\u002Fcode> for \u003Ccode>jane@gmial.com\u003C\u002Fcode>, and a \u003Ccode>checks\u003C\u002Fcode> object with \u003Ccode>syntax\u003C\u002Fcode>, \u003Ccode>mx\u003C\u002Fcode>, \u003Ccode>smtp\u003C\u002Fcode>, \u003Ccode>catch_all\u003C\u002Fcode>, \u003Ccode>disposable\u003C\u002Fcode>, \u003Ccode>role\u003C\u002Fcode> and \u003Ccode>free_provider\u003C\u002Fcode>. In \u003Ccode>fast\u003C\u002Fcode> mode no mailbox check runs, so the best status is \u003Ccode>unknown\u003C\u002Fcode> with the reason \u003Ccode>smtp_not_checked\u003C\u002Fcode>. In \u003Ccode>full\u003C\u002Fcode> mode the mail server is asked about the mailbox without sending anything. Both cost 1 credit, and errors are not billed. The \u003Ca href=\"\u002Fdocs\u002Fapi-reference\u002Femail\">email API reference\u003C\u002Fa> lists every status and reason.\u003C\u002Fp>\n\u003Cp>A sensible form flow looks like this:\u003C\u002Fp>\n\u003Col>\n\u003Cli>\u003Cstrong>While typing:\u003C\u002Fstrong> run the local pattern. Show a quiet hint on a clear mistake, and never block typing.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>On submit, on your server:\u003C\u002Fstrong> call the API. Reject \u003Ccode>undeliverable\u003C\u002Fcode> with the reason, offer \u003Ccode>did_you_mean\u003C\u002Fcode> when there is one, and decide your policy for \u003Ccode>risky\u003C\u002Fcode>.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>After signup:\u003C\u002Fstrong> send a confirmation email when the address will be used to sign in.\u003C\u002Fli>\n\u003C\u002Fol>\n\u003Cdiv class=\"code-block\" data-code-block>\u003Cdiv class=\"code-head\">\u003Cspan class=\"code-label\">javascript\u003C\u002Fspan>\u003C\u002Fdiv>\u003Cpre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\">\u003Ccode class=\"language-javascript\">\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">async\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> function\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\"> checkEmail\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">email\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">) {\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">  if\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> (\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">!\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">looksLikeEmail\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(email)) \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">return\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> { ok: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">false\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, hint: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">'format'\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> }\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">  const\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> response\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> =\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> await\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\"> fetch\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">'https:\u002F\u002Fapi.qelka.com\u002Fv1\u002Femail'\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, {\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">    method: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">'POST'\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">,\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">    headers: {\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">      Authorization: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">`Bearer ${\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">process\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">.\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">env\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">.\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">API_KEY\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">}`\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">,\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">      'Content-Type'\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">'application\u002Fjson'\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">,\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">    },\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">    body: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">JSON\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">.\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">stringify\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">({ email, mode: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">'fast'\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> }),\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">    signal: AbortSignal.\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">timeout\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">5000\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">),\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">  }).\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">catch\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(() \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=>\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> null\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">  if\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> (\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">!\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">response \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">||\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> !\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">response.ok) \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">return\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> { ok: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">true\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, unchecked: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">true\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> }\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">  const\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> result\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> =\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> await\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> response.\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">json\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">()\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">  if\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> (result.status \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">===\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> 'undeliverable'\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">) \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">return\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> { ok: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">false\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, hint: result.reason, suggestion: result.did_you_mean }\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">  return\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> { ok: \u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">true\u003C\u002Fspan>\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, status: result.status, suggestion: result.did_you_mean }\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">}\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fcode>\u003C\u002Fpre>\n\u003C\u002Fdiv>\n\u003Cp>The function fails open: if the API is slow or unreachable, the form goes through and the address can be checked later. A validation outage should not be the reason nobody can sign up. Call the API from your server, never from the browser, or your key ships to every visitor. For the signup side see \u003Ca href=\"\u002Fdocs\u002Fguides\u002Fvalidate-signup-forms\">validate signup forms\u003C\u002Fa>.\u003C\u002Fp>\n\u003Ch2 id=\"mistakes-to-avoid\">\u003Ca class=\"heading-link\" href=\"#mistakes-to-avoid\">\u003Cspan>Mistakes to avoid\u003C\u002Fspan>\u003C\u002Fa>\u003C\u002Fh2>\n\u003Cul>\n\u003Cli>\u003Cstrong>A heroic regex copied from a forum.\u003C\u002Fstrong> It rejects real addresses and still accepts every typo.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Rejecting the plus sign.\u003C\u002Fstrong> It turns away people who use tagged addresses.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>A length limit of 50.\u003C\u002Fstrong> Real addresses are longer. Use the RFC limits.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Blocking submit on a pattern failure with no explanation.\u003C\u002Fstrong> Say what is wrong.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Treating a regex pass as a reason to send a campaign.\u003C\u002Fstrong> Deliverability is a different question: see \u003Ca href=\"\u002Fblog\u002Femail-bounce\">email bounce\u003C\u002Fa>.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Validating only in the browser.\u003C\u002Fstrong> Anyone can post to your endpoint directly.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Ch2 id=\"try-it\">\u003Ca class=\"heading-link\" href=\"#try-it\">\u003Cspan>Try it\u003C\u002Fspan>\u003C\u002Fa>\u003C\u002Fh2>\n\u003Cp>The free \u003Ca href=\"\u002Ftools\u002Femail-syntax-checker\">email syntax checker\u003C\u002Fa> runs the format check on any address, and the \u003Ca href=\"\u002Ftools\u002Femail-verifier\">email verifier\u003C\u002Fa> runs the full set after you create a free account. The \u003Ca href=\"\u002Femail-verification-api\">email verification API\u003C\u002Fa> page covers pricing and volumes.\u003C\u002Fp>\n",[11,15,19,22,25,28,31,34,37],{"id":12,"text":13,"depth":14},"what-the-standards-say-an-address-is","What the standards say an address is",2,{"id":16,"text":17,"depth":18},"why-the-full-grammar-is-a-poor-regex","Why the full grammar is a poor regex",3,{"id":20,"text":21,"depth":14},"a-practical-pattern","A practical pattern",{"id":23,"text":24,"depth":14},"what-a-regex-cannot-know","What a regex cannot know",{"id":26,"text":27,"depth":14},"internationalized-addresses","Internationalized addresses",{"id":29,"text":30,"depth":14},"case-whitespace-and-the-plus-sign","Case, whitespace and the plus sign",{"id":32,"text":33,"depth":14},"then-run-the-checks-that-matter","Then run the checks that matter",{"id":35,"text":36,"depth":14},"mistakes-to-avoid","Mistakes to avoid",{"id":38,"text":39,"depth":14},"try-it","Try it",[41,44,47,50,53,56],{"q":42,"a":43},"What is the best regex to validate an email address?","There is no perfect one, because the grammar in RFC 5322 is too permissive and too intricate for a readable pattern. For a form, use something short that catches obvious mistakes, such as the pattern the HTML standard uses for \u003Ccode>input type=email\u003C\u002Fcode>, or even a check for one \u003Ccode>@\u003C\u002Fcode> with text on both sides. Then verify the domain and the mailbox, which no pattern can do.",{"q":45,"a":46},"Can a regex tell me if an email address exists?","No. A regex reads characters. It accepts \u003Ccode>nobody@example.com\u003C\u002Fcode> as readily as a real mailbox, and it accepts typos like \u003Ccode>jane@gmial.com\u003C\u002Fcode>. Whether a domain receives mail is a DNS question, and whether a mailbox exists is a question for the mail server. A regex only filters out strings that cannot be an address.",{"q":48,"a":49},"How long can an email address be?","RFC 5321 limits the local part, before the \u003Ccode>@\u003C\u002Fcode>, to 64 octets and the domain to 255 octets, and caps the whole forward path at 256 octets including its angle brackets, which in practice means about 254 characters for the address. The Qelka API accepts up to 320 characters as input, so an over-long string gets a clear verdict instead of an error.",{"q":51,"a":52},"Should I allow plus signs and unusual characters in the local part?","Yes. A plus sign is common for subaddressing, as in \u003Ccode>jane+shop@example.com\u003C\u002Fcode>, and RFC 5322 allows many other symbols. Rejecting them turns away real customers and breaks users who rely on tagged addresses. Do not strip the tag either: the provider decides how to deliver, and the address you store should be the one the person typed.",{"q":54,"a":55},"Do email regexes support international characters?","Most do not. Pre-2012 patterns assume ASCII. RFC 6531 extends SMTP so that local parts can hold UTF-8 and domains can be internationalized, and both are in use. A pattern that only accepts \u003Ccode>a-z\u003C\u002Fcode> rejects those users. If you serve markets where non-ASCII addresses are normal, test your validator with them before launch.",{"q":57,"a":58},"What should I do after the regex passes?","Verify the address with checks a pattern cannot do. Look for a typo in a known domain, confirm that the domain has mail servers, ask the mail server whether the mailbox exists, and flag disposable and role addresses. Qelka's email API runs all of them in one call and returns a status and a reason. Then send a confirmation email when the address will be used for sign-in.","2026-11-24",18,1408,{},1795559739875]