Forms · Glossary

What is form validation?

Form validation is the set of checks an answer must pass before a form accepts it: a required field is filled, a number sits within range, text is not too long, a file is the right type and size. Client side checks run in the browser while people fill in the form; server side checks run again when it arrives.

Validation is what separates a form that collects usable answers from one that collects whatever was typed. Done badly it is also the most common source of frustration on a form, because a rule that rejects a real answer blocks the very person the form was built for.

· Co-founder

6 min read · Published

The validation rules this form builder offers, and where each is checked
RuleSet onChecked in the browserChecked on the server
RequiredAny input fieldClassic: on submit. Conversational: when Next is pressedYes, on every submission
Minimum and maximum lengthShort text and long textNoYes, plus a 20,000 character cap on any text
Minimum and maximum valueNumberClassic: yes. Conversational: noYes
Answer is one of the optionsDropdown, radio buttons, checkboxesThe control only offers the optionsYes
File type, size and countFile upload: images and PDF toggles, up to 10 files, up to 100 MB eachYes, when files are chosenA general upload check rather than the field's own settings
Regex patternNo setting in the builderNoNo

Two jobs in two places

Checks in the browser and checks on the server exist for different reasons, and a form needs both. Browser checks are about the respondent: they catch a missed question or an impossible date while the person is still looking at the field, which is faster and kinder than a rejection after pressing submit. Server checks are about trust. MDN says plainly that client side validation should not be considered an exhaustive security measure, because it is too easy to bypass, and the OWASP input validation guidance adds that anything done in JavaScript can be circumvented by somebody who turns it off or sends the data directly. Whatever the browser allows through, the server has to decide again before the answer is stored.

The checks worth having

OWASP separates two levels. Syntactic validation checks that a value has the right shape, such as a date that is a real date or a postcode made of digits. Semantic validation checks that it makes sense in context, such as an end date that falls after the start date or a quantity that does not exceed stock. Most forms need a small set of syntactic rules: required answers present, numbers within a sensible range, text within a length that fits wherever it is going, files of an expected type and size, and choices restricted to the listed options. Semantic rules usually belong in the system that receives the data, because that is where the context lives, and they are where the most useful error messages come from. Keep the list short. Every rule is a chance to reject somebody who was trying to give a real answer, so each one should protect something specific: a record that would otherwise be unusable, a system that would otherwise break, or a follow up email that would otherwise be needed.

Be strict about meaning, relaxed about format

The W3C forms tutorial advises being liberal with input, because people write phone numbers, dates and postcodes in many legitimate ways. The GOV.UK Design System makes the same point with postcodes, which should be accepted with or without a space. The better approach is to tidy the value before checking it: remove spaces from a card number, trim the ends of an email address, accept lower case where upper case is stored. Rules that reject real answers are the worst kind of validation. OWASP gives the example of a denylist that blocks an apostrophe and so rejects a surname like O'Brian, and the same thing happens with hyphenated names, long addresses and international phone numbers.

Error messages that help

WCAG 2.2 success criterion 3.3.1 requires that a detected error is identified and described to the user in text, and 3.3.3 adds that a suggestion for fixing it should be offered where one is known. In practice that means the message names the field, says what is wrong and says what would be right: enter a date after the start date, rather than invalid input. GOV.UK recommends an error summary at the top of the page with focus moved to it, a message beside each field, and keeping everything the person already entered. It also turns off the browser's built in messages with novalidate so that every error looks and reads the same way.

Validation in this builder

The Validation settings on a field offer a Required Field switch, minimum and maximum length on short and long text, and minimum and maximum value on number fields, while file uploads have their own limits. The table above shows where each rule runs. Two gaps are worth knowing before you rely on them. A conversational number field does not stop an out of range value in the browser, so the range is only enforced when the form is submitted. And there is no regex pattern setting, so a format such as a membership number cannot be enforced by the form itself. On every submission the server also drops answers for any field that is not part of the published version the person filled in.

Questions people ask

Is the browser's built in validation enough?

It is a good first layer and not a complete one. Attributes such as required, minlength, maxlength, min, max and pattern give instant feedback without any code, but the messages look different in every browser, they are not always announced well by screen readers, and they can be removed by anyone who edits the page. Keep them for convenience and repeat every rule on the server.

Should email addresses be checked with a regular expression?

Only loosely. A pattern that insists on something before an at sign and a dot after it catches typing slips, but a pattern that tries to match every legal address will either reject real ones or accept nonsense. OWASP suggests a basic check followed by passing the address to the mail system, and the only true test is sending a message that somebody has to open.

What is the difference between validation and verification?

Validation checks that an answer is acceptable in form: the right shape, within range, present when required. Verification checks that it is true: the email address belongs to the person, the ABN is registered, the phone number rings. A form can validate on the spot, while verification usually needs a second step such as a confirmation link, a code or a lookup.

Does validation stop spam submissions?

Not much. Automated scripts that post directly to a form's endpoint skip the browser entirely, and server rules only reject submissions that break them, which a well written bot will not. Validation keeps bad data out of your records; spam needs different tools, such as access controls, rate limits or checks designed specifically to tell people from scripts.

What is input sanitisation, and is it the same thing?

Sanitisation changes a value to make it safe or tidy, for example trimming spaces or escaping characters before displaying text on a web page. Validation decides whether to accept the value at all. The two work together: tidy the input so small format differences do not cause rejections, then validate what remains, and escape it again wherever it is displayed.

Can validation depend on another answer?

Yes, and those cross field rules are often the most valuable, such as a return date that must follow a departure date or a total that must match its parts. They are harder to build in a form builder, which usually validates one field at a time, so they often live in the system that receives the submission and follows up when something does not add up.

Make one with forms

The button opens the generator with this use case already described. Change the wording to match your own.

Create a form with OneCraft

Related questions

Step by step in the builder: Every form field and when to use it, then Create a form from scratch with AI.

Sources

Written and checked by the OneCraft team. Last checked .