Good contact form validation checks only what matters, explains every problem in plain words next to the field, and keeps what the person already typed. Check answers in the browser for speed and again on the server for safety, accept phone numbers with a country code and real-world email addresses, tie each error to its field for screen readers, move focus to the first problem, and stop spam with invisible checks and rate limits rather than puzzles.
Purpose
What validation is for
Validation has two honest jobs. It catches mistakes that would stop you from replying, such as an email address with a missing letter, and it protects your inbox and your systems from input that is broken or malicious. Anything beyond those two jobs deserves a second look.
Most bad validation comes from trying to make answers tidy. Rejecting a name because it contains an apostrophe, a phone number because it has spaces, or an email address because its domain is unfamiliar does not make your data better. It just means the enquiry never arrives, and you never find out.
So the rule of thumb is simple: be strict where a wrong answer would truly hurt, and generous everywhere else.
Error messages
Write error messages people can act on
An error message is a small piece of customer service. Treat it like one.
Say what is wrong and how to fix it.
Instead of "Invalid input", write "Please enter an email address, for example name@example.com". The person should know exactly what to change.
Show the message next to the field.
An error at the top of the page alone forces people to hunt. Put it directly under or beside the field that needs attention.
Do not rely on colour alone.
A red border is easy to miss, and some people cannot tell red from green. Use words, and an icon if you like, as well as colour.
Keep everything the person typed.
Clearing a long message because one field was wrong is the fastest way to lose an enquiry.
Check at the right moment.
Showing an error while someone is still typing feels like being interrupted. Check a field when they leave it, and check everything again when they press send.
Stay polite and plain.
No blame, no jargon, no codes. "This field is required" is fine; "Please tell us your name so we know who to reply to" is better.
Browser and server
Validate in the browser and again on the server
Checks in the browser give fast, friendly feedback before the form is sent. They are a courtesy, not a safeguard: anyone can switch off scripts or send data to your site without using the form at all. Automated spam does exactly that.
Checks on the server are the ones you can rely on. The server should apply the same rules as the browser, and more: limits on length, removal of hidden control characters, and a refusal of anything that does not match what the field expects. If the server rejects something, the form should still show a clear message, not a blank page.
The two layers should agree. If the browser accepts an answer that the server then refuses, people see a confusing failure after pressing send. Writing the rules once and applying them in both places avoids that.
Common fields
How to check the fields people actually fill in
Phone
International phone numbers
Offer a country code dropdown and let people type the rest with spaces or dashes if they like. International numbers, including the country code, are at most 15 digits under the ITU E.164 standard, so a sensible digit count catches typos without rejecting real numbers.
Email addresses
Check for one @ and a domain with a dot, then stop. Real addresses can include plus signs, dots, numbers and long or new domain endings. Over-strict patterns reject real customers.
Name
Names
Accept letters from any script, spaces, hyphens and apostrophes. Names such as O'Brien, Nguyen Van An or a single name are all real. Check only that the field is not empty and not absurdly long.
Postal code
Postal codes
Formats differ widely: SW1A 1AA in the UK, K1A 0B1 in Canada, six digits in India, seven in Japan, and none at all in Hong Kong. Use a strict format only if you serve one country.
Dates
Dates and times
A date picker avoids day-first and month-first confusion. If a date must be in the future, such as a booking, refuse past dates and say why.
Links
Website links
Accept addresses that start with http or https. Refuse anything else, which keeps out links that could run code when someone clicks them.
Accessibility
Make every error usable with a keyboard and a screen reader
These habits follow the error and label guidance in WCAG 2.2, the web accessibility standard.
Give every field a visible label.
Text inside the box that disappears when typing starts is not a label. Put the label above the field and connect it in the code.
Tie each error to its field.
Link the error text to the input, for example with aria-describedby, and mark the field as invalid with aria-invalid, so a screen reader reads the problem when the field gains focus.
Move focus to the first error.
When someone presses send and something is wrong, place the cursor in the first field that needs fixing. Keyboard and screen reader users then start in the right place.
Mark required fields in words.
An asterisk alone can be unclear. Say "required" or "optional" in the label, and explain the convention once at the top of the form.
Help the browser help people.
Use the right input types and autocomplete hints for name, email and phone, so phones show the right keyboard and browsers can fill details in.
Spam
Stop spam without puzzles
Picture puzzles and distorted text stop some bots, but they also stop people: those with low vision, those on a small phone screen, and those who simply give up. WCAG 2.2 asks that signing in should not depend on a test such as transcribing distorted text unless an alternative exists, and the same thinking suits a contact form.
Quieter defences work well together. An invisible check runs in the background and asks real visitors for nothing. Rate limits cap how many messages one source can send in a short time. Server-side limits on length and content reject junk before it reaches your inbox.
No defence catches everything, so keep an eye on what still gets through and adjust. The guide on stopping contact form spam covers this in more depth.
Custom formats
Strict formats belong only where the answer really is strict
Some fields really do have a fixed shape: a booking reference, an order number or a membership code. For these, a format rule is a help, because it catches a mistyped code before you waste time looking it up. The error message should show an example of the right shape.
Other fields only look fixed. A field set to letters only will reject a name with a hyphen or a street with a number. A field set to digits only will reject a phone number typed with a plus sign. Before adding a format rule, think of three real customers in three countries and check that all of them could pass.
Test your own form with awkward but real answers: a long name, a name in another script, a phone number from abroad, an email address with a plus sign. If any of them fails, the rule is too strict.
In Folio
How validation works on a Folio contact form
Every answer is checked twice.
Your site checks each answer in the browser as visitors fill in the form, and again on the server when it arrives.
Phone fields include a country code dropdown with flags.
Visitors choose their country and type the number, and you can add an alternate phone field too.
Text fields can use a format.
In Inbox, then Lead form, a text field can use letters only, digits only, postal code, letters and numbers, reference code, or a custom pattern. Use these only where the answer really has a fixed shape.
Date fields can refuse past dates.
Useful for bookings and quote requests, so nobody picks a day that has already gone.
Spam is handled quietly.
An invisible check and rate limits protect the form, with no puzzles for visitors to solve.
Frequently asked questions
What is contact form validation?
It is the set of checks that make sure each answer on a form is usable before it is accepted, such as a real-looking email address or a filled-in required field, with clear messages when something needs fixing.
Is browser validation enough?
No. Browser checks give quick feedback, but they can be bypassed. Always check every answer again on the server, using the same rules, before you store or send it.
How should I validate international phone numbers?
Use a country code dropdown, allow spaces and dashes, and check a sensible number of digits. Under the E.164 standard an international number is at most 15 digits including the country code.
How strict should email validation be?
Light. Check for an @ and a domain with a dot. Stricter patterns tend to reject real addresses with plus signs, subdomains or new domain endings.
Where should form error messages appear?
Next to the field that needs fixing, in plain words, linked to the field in the code so screen readers announce it. When the form is sent with errors, move focus to the first one.
How do I stop contact form spam without a captcha puzzle?
Combine an invisible background check, rate limits on how often one source can send, and server-side limits on length and content. Real visitors see nothing, and most automated junk is refused.