Recent chats
ASKGEEZ Q&A GUIDETechnology & devices

How can I validate a form without blocking users who need to correct errors?

Quick answer

Choose validation timing that helps people correct mistakes without interrupting every step: for example, check a field after it is completed or validate the form on submission. Explain what needs attention and how to fix it, identify the affected field, and preserve entered values when showing errors. Browser messages vary, so provide clear feedback of your own. Keep server-side validation too; browser checks alone are not sufficient. [S1] [S2]

LET’S WORK THROUGH IT

The question, the details, the next step.

Question

How do I choose when to show validation errors? I don’t want someone interrupted while filling out a form, but I also don’t want them to submit it and face a long list of surprises.

Geez

Choose the timing according to the kind of mistake and the form’s flow. A practical starting point is to avoid showing an error for an untouched field. You can check a field after someone has entered a value and moved on, then validate relevant fields when they submit. For a short form, a clear message after submission may be enough; for a longer form, consider feedback beside each field so people can find the problems.

Treat these as design choices to review with your form, not universal rules. Avoid repeatedly interrupting someone while they are still typing. If a check depends on multiple fields or information available only after submission, explain the issue when you can evaluate it. Browser-native validation can block submission and show a message, but its appearance depends on the browser. [S1]

Follow-up question

What should the actual error say? Some fields have rules that aren’t obvious from the label, and a generic “invalid input” message isn’t helpful.

Geez

Make the message say both what needs attention and what action can fix it. Put the instruction close to the affected field. For example, instead of “Invalid date,” use “Enter the date as day, month, and year,” if that is the format your form accepts. Instead of “Required,” try “Enter your delivery address,” when that describes what is missing.

Use wording that matches the actual rule; don’t imply a value is acceptable if the application will reject it. A submission-level summary can point out that fields need attention, while each field’s message gives its specific correction. MDN recommends helpful, clear correction information. It also notes that browser-default messages can vary by browser and locale and have no standard CSS styling. [S1]

Follow-up question

If the server finds a problem after submission, what should happen to everything the person already filled in?

Geez

Return the form with the entered values preserved, mark the fields that need correction, and show relevant messages. Don’t make someone re-enter unrelated information because one field failed. The application must preserve values when handling errors; validation features do not do this automatically. [S1]

Before release, test the error response itself—not just the validation rule. For example, fill several fields, enter one deliberately invalid value, and submit. Check that the other values remain available and that the person can correct the problem and continue. This tests recovery as well as whether the rule catches the invalid value.

Follow-up question

Can I rely on HTML or browser validation to stop bad submissions? I’d like one consistent approach for the whole form.

Geez

Use browser-side checks to give feedback, but don’t treat them as the final safeguard. HTML attributes can express basic constraints, and the Constraint Validation API supports more complex checks. Its methods include checkValidity() to test constraints, reportValidity() to report failures, and setCustomValidity() to set a custom error message; an empty string clears that message. Interactive validation can occur on submission. Client-side constraints can be bypassed, so the server must validate submitted data too. [S2]

A review plan you can reuse:

  1. List each field’s actual rule and a plain-language correction.
  2. Decide when each rule should appear: after a completed field, on submission, or both.
  3. Check that errors identify the affected field and explain how to fix it.
  4. Test a failed submission and confirm other entered values remain available.
  5. Check that server-side validation is in place as well as browser feedback.

Example review note: “Postal code: show the format hint before submission; if rejected, keep the entered address and explain the accepted format beside the field.” Replace that example with the actual rule for your form. The best timing and wording depend on the form, so review those choices with representative tasks.

A practical checklist

  • Write down the real rule for every field and the correction a user can make.

  • Choose whether feedback appears after field completion, on submission, or at both points.

  • Use specific messages beside affected fields and make any submission summary actionable.

  • Test an invalid submission and verify that unrelated entered values remain intact.

  • Validate on the server as well as in the browser.

A few more useful answers

Should errors appear while someone is typing?

Not necessarily. Consider waiting until the field is completed or the form is submitted so feedback does not interrupt entry. Choose and review timing that fits the field and form.

Can I customize the browser’s built-in validation message?

The Constraint Validation API includes setCustomValidity() for setting a custom message; an empty string clears it. Browser feedback can vary, so check that the result is clear in your interface. [S1] [S2]

Does keeping form values after an error happen automatically?

No. The application must preserve entered values when it handles an error response. Test that behavior with a failed submission rather than assuming the validation feature handles it. [S1]

Sources

References used for this guide.

  1. [S1] Client-side form validation — MDN Learn web development
    developer.mozilla.org · Checked
  2. [S2] Using HTML form validation and the Constraint Validation API — MDN
    developer.mozilla.org · Checked

YOUR QUESTION. YOUR DETAILS.

Let’s work through your situation.

Get a tailored answer or help with your next task. Starts at $1, with a quote before you pay.

Ask your own question
← Back to Geez at Work