Integrations · Forms
Form guard: check email fields with one script tag
Add one script tag to any page with a sign-up or contact form. It looks at every email field when the visitor has finished typing, offers a one-click fix for typos such as gmial.com, and stops the form only when the address cannot receive mail or is a throwaway inbox. Everything else goes through, and so does every submission when something goes wrong.
<script src="https://email-validation.org/guard/v1.js" data-key="YOUR_BROWSER_KEY" defer></script>Replace YOUR_BROWSER_KEY with a browser key (below). No build step, no dependencies, no cookies: the script is 5.0 kB compressed and loads from https://email-validation.org only.
Try it
This demo runs the same script in this page. It answers only the free test addresses on sandbox.email-validation.org, in your browser, with the answers the API gives for them: it sends nothing and checks no real address. Any other address passes unchecked, as it would with a key that has no credits left.
Try one (click to fill the field, then leave it or press Sign up):
The demo needs JavaScript.
Set it up in two minutes
In the dashboard, open API keys, choose Create key and pick On a public web page as where you will use it. That makes a browser key, which can only validate addresses:
- Allowed origins: your site, such as
https://www.example.comandhttps://example.com, plus any test address you use. - Daily credit cap: a little above the sign-ups you get on a busy day.
A browser key needs both. The script works only with a browser key: with any other key it checks nothing and says so once in the browser console, because a key in a page can be read by anyone. If a normal key was ever in a public page, roll it under API keys. A key made before 16 November 2026 needs a roll to work here too.
- Allowed origins: your site, such as
Paste the tag above into your page, before
</body>or in<head>, with your key indata-key.Test it with the free test addresses:
no_mailbox@sandbox.email-validation.orgshows the message and stops the form,likely_typo@sandbox.email-validation.orgalso offers a fix, andaccepted@sandbox.email-validation.orggoes through. Do not send a form with a test address that goes through where its sign-up gets an email (a confirmation, a welcome, a newsletter): test addresses receive no mail, and the bounce hurts your sending.
If your account processes data in the EU only, add data-region="eu": the checks then go to https://api-eu.email-validation.org (EU data residency).
What it does
- Looks once the visitor is done. A field is looked at when the visitor leaves it or the value changes (typing, pasting, autofill or a password manager), and again on submit. Never on every keystroke. A typed address is checked when the visitor leaves the field, even if the form is never sent.
- Fixes typos for free. A domain one or two letters away from a big mailbox provider (the script knows 55 of them) gets "Did you mean …?" with the fixed address as a button. The suggestion is worked out in the browser, without an API call; the visitor accepts it with one click or tap, or with Enter or Space on the button. A domain that is already a known provider is never "corrected".
- Stops only what you choose. By default
invalidanddisposableresults stop the form, with a short message next to the field, andcatch_allresults go through. You can stop any ofinvalid,disposable,catch_all.validresults (also those with a warning, such as a role address) andunknownresults always go through. - One check per address. Each address is checked at most once while the page is open: leaving the field again, pressing submit twice or a second form never pays for it again (
EVGuard.configurestarts afresh). - Never breaks your form. No answer within 3 seconds, a network error, a refused key, a key that is not a browser key, no credits left, a rate limit or any unexpected answer: the field passes and the form submits. After a refused key or with no credits left, the script stops checking on that page. A form that opens in a new tab or window is never held up; only an address already known to be stopped stops it.
- Accessible. The message is announced by screen readers (
aria-live), linked to the field (aria-describedby), and the field is markedaria-invalidwhile it stops the form; on a stopped submit the field gets the focus. The message appears after the visitor moves on (after the mouse button is released), so a click or tap on the submit button lands where it was aimed.
Each completed check uses a credit (1 credit = 1 validated address); unknown results, errors, the test addresses and the typo suggestions are free.
Your key on a public page
The key sits in your page's source, so treat it as public. What a browser key with allowed origins does:
- Stops other websites. The API refuses the key when a browser sends it from any origin not on its list (
403 forbidden_origin), so another site cannot use your key in its visitors' browsers. - Does not stop scripts outside a browser. The allowed origins are checked against the
Originheader, which a browser always sets truthfully but a script on a server can set to anything. Anyone who copies the key can spend checks with it, and so can a bot that fills in your form. The key's daily credit cap is what limits the cost: set one. If you see a key being misused, roll it under API keys and paste the new one.
A browser key only validates addresses: it cannot read your usage or start bulk lists. Each check's answer does show your account's remaining credits (the X-Credits-Remaining header), so anyone with the key can see that number. If keeping the key off the page matters more than the instant message, check the address on your server instead (sign-up forms).
Options
On the script tag:
data-key: your browser key. Without it the script still offers typo fixes, but checks nothing.data-region="eu": send checks tohttps://api-eu.email-validation.org.data-stop: the results that stop the form, separated by spaces:invalid disposableby default, for exampleinvalidorinvalid disposable catch_all;nonestops nothing (messages and fixes only).data-auto="off": guard only the fields markeddata-ev-guard, not everyinput type="email".data-msg-invalid,data-msg-disposable,data-msg-catch-all: your own wording for each message.data-msg-suggest: the typo line, where{suggestion}is the fixed address.
The default messages:
invalid: "This address cannot receive email. Please check it."disposable: "Please use a permanent address, not a disposable one."catch_all: "We could not confirm this address. Please use another one."
On a field:
data-ev-guardguards a field that is nottype="email"(a text field), or any field withdata-auto="off".data-ev-guard="off"on a field, its form or any element around it leaves it alone.data-ev-guard-message="ID"shows the message in the element with that id (keep it empty: the script replaces its content). Without it the message goes right after the field, or after the field's row when the field sits in a row with other elements (such as an email box and its button side by side).
For single-page apps
New email fields that appear later are guarded automatically. The script also adds window.EVGuard:
EVGuard.attach(element); // guard a field, or every email field inside an element
EVGuard.detach(element); // stop guarding (a field added again is guarded again: use data-ev-guard="off" for good)
EVGuard.check(fieldOrAddress).then((verdict) => { /* … */ }); // check now (waits at most the same seconds)
EVGuard.configure({ key: '…', stop: ['invalid'], messages: { invalid: '…' } });
document.addEventListener('ev-guard', (event) => {
const { address, status, stop, suggestion, message, error } = event.detail;
});The ev-guard event fires on the field (and bubbles) each time its verdict changes. status is one of the five statuses or null when there is no answer (error then says why, for example timeout); stop is true only for a status you chose to stop; suggestion is a fixed address or null.
The script stops a submit only for a real <form> submission. If your app sends the form from a click handler instead, call EVGuard.check(field) there and go on unless stop is true.
Styling
The message is a span.ev-guard-msg with data-state="stop" or "hint"; the fix is a button.ev-guard-fix. Its text uses your page's colour, so it reads in light and dark themes. Your own CSS always wins (the script's rules have zero specificity), or set these custom properties:
:root {
--ev-guard-color: inherit; /* message text */
--ev-guard-accent: #d92d20; /* the bar beside a stopping message */
--ev-guard-hint-accent: #2f6fed; /* the bar beside a typo fix, and its focus ring */
--ev-guard-font-size: 0.875em;
--ev-guard-gap: 0.25em; /* space above the message */
}Once a message has appeared, its line keeps its height when the message clears, so the button below does not jump.
Content Security Policy
The script uses no inline script, no eval and no inline styles (its styles go in a constructed stylesheet, which style-src does not govern), and works with Trusted Types. Add:
script-src https://email-validation.org/guard/connect-src https://api.email-validation.org(orhttps://api-eu.email-validation.orgwithdata-region="eu")
No style-src entry is needed.
Subresource Integrity
https://email-validation.org/guard/v1.js gets fixes without a new tag, so its bytes can change. To pin the exact file with Subresource Integrity, use this version's frozen URL; its bytes never change:
<script src="https://email-validation.org/guard/v1.1.1.js" data-key="YOUR_BROWSER_KEY"
integrity="sha384-SUD8ahzwiY5wOxMuiNNZiH+LjvNXla+QRCb4A2YIAVAzKQmWN1F7fzY64hSHQyZ/" crossorigin="anonymous" defer></script>Version 1.1.1. A change that would break existing pages gets a new URL (/guard/v2.js), and the old ones keep working. Both files are served with CORS and Cross-Origin-Resource-Policy: cross-origin, so pages with cross-origin isolation can load them.
What the visitor's address is used for
When the visitor leaves the field or submits the form, the script sends the address in the field to https://api.email-validation.org in the body of a POST request (never in a URL), with your key and the API's timeout setting, and nothing else. That is one of your API checks, handled like any other check you make with the API: the address is processed for you to give you its result. The visitor's browser also sends your page's origin, which is how the allowed origins work, and like any request it reaches us from the visitor's IP address. The script sets no cookie, uses no browser storage, writes nothing to the console (except one warning when its key is not a browser key) and loads nothing from anyone else. Typo fixes and the test addresses in the demo above never leave the browser. See the privacy policy and the DPA.
Related
- React, Vue, Svelte, Webflow, Framer and Shopify themes: the same script as a component or a paste-in
- Sign-up forms: checking on your server instead
- Test addresses and limits per key
- Statuses and POST /v1/validate