Skip to main content

Claude Prompt to Build Accessible Form Validation UX

Implement form validation with real-time feedback, accessible error messages, progressive disclosure and delightful micro-interactions for any form.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt
Design and implement a form validation system for a multi-step user registration with payment form in a React with React Hook Form and Zod application. The form has 18 fields across 3 (personal info, company details, payment) steps and collects PII and payment card information data. Build the validation UX: 1) Define the validation strategy per field: use blur-then-change (lazy-eager pattern) timing — validate on blur for first interaction, then switch to validate-on-change after the first error so users get immediate feedback while correcting. For email (uniqueness check) and username (availability check), implement debounced async validation with a loading spinner and cache results. 2) Design error message patterns: place error messages directly below the field with aria-describedby linking, use inline text with error icon, field border color change, and subtle background tint styling with a red-600 color (not just red text — include an icon), animate messages in with a subtle slide-down, and write messages in plain language: "Email address is required" not "Validation failed: required field." Create 25 custom messages that sound human. 3) Implement field-level validation states with visual indicators: untouched (default), active (focus ring), valid (green checkmark with subtle scale-in animation), invalid (red border with shake micro-animation on submit attempt), and warning (amber for non-blocking issues like weak password). 4) Build progressive disclosure validation for the password (strength meter) and credit card (format preview): show requirements upfront (e.g., password strength meter with rules list), check off requirements in real-time as the user types, and only show the submit button when all required fields are valid. 5) Create a form-level validation summary that appears on submit attempt: an accessible alert region (role="alert") listing all errors as links that focus the corresponding field when clicked. Support ARIA live regions with polite announcements announcements for error count changes. 6) Handle edge cases: prevent double submission with button state management, preserve form data on accidental navigation (beforeunload + sessionStorage with automatic restore on page load), handle server-side validation errors by mapping them to fields, and display a generic error banner for unexpected failures. 7) Add success patterns: on valid submission show a confetti animation with a success message and redirect countdown confirmation, disable the form to prevent resubmission, and handle the redirect or next-step transition.

What this prompt does

This prompt designs and implements an accessible form validation system for a [form_type] form in a [framework] app, spanning [field_count] fields across [step_count] steps. It defines the validation strategy per field, error message patterns, visual field states, progressive disclosure for complex fields, a form-level error summary, edge-case handling, and success patterns. The result treats validation as a real feature, so long forms feel forgiving instead of punishing.

The variables tune timing and feedback. [validation_timing] implements a lazy-then-eager pattern, validating on blur first, then on change after the first error, so users are not nagged mid-typing. [async_fields] get debounced async checks with caching and a loading spinner, [error_position] and [error_style] define where and how messages appear, and [custom_messages] ensures plain-language copy that names the fix. [multi_step_fields] drives progressive disclosure like a password strength meter that checks off rules in real time, while [screen_reader] and [persistence_method] cover accessibility and data preservation across the [step_count] steps.

When to use it

  • Building a multi-step signup or checkout where validation needs to feel forgiving.
  • Implementing the lazy-then-eager [validation_timing] pattern instead of validating on every keystroke.
  • Adding accessible error handling with a role="alert" summary that focuses the offending field.
  • Showing real-time requirement checklists for [multi_step_fields] like passwords.
  • Handling async uniqueness checks on [async_fields] without hammering the server.
  • Preserving entered data across accidental navigation with [persistence_method].

Example output

You get a validation implementation plan with code: per-field rules using the [validation_timing] lazy-eager pattern, debounced async validation with caching for [async_fields], error messages placed [error_position] with [error_style] styling and plain-language copy ([custom_messages] of them), field states (untouched, active, valid, invalid, warning) with subtle animations, progressive disclosure for [multi_step_fields], an accessible role="alert" summary linking to each error field, edge-case handling for double submission and navigation via [persistence_method], and a [success_feedback] confirmation.

Pro tips

  • Use the [validation_timing] lazy-eager pattern; validating on blur first and on change only after an error is the key to a forgiving feel.
  • Write [custom_messages] in plain language that names the fix ("Email address is required"), not internal jargon like "validation failed."
  • Debounce [async_fields] and cache results so a uniqueness check does not fire on every keystroke or repeat needlessly, and show a spinner while it runs.
  • Make the error summary a real role="alert" region with links that focus each field; this is what makes the form usable with a screen reader and keyboard alone.
  • Preserve data via [persistence_method] before any beforeunload, so an accidental back navigation does not wipe a long form.
  • Map server-side validation errors back onto specific fields rather than only showing a generic banner, and prevent double submission with button state management on submit.

Frequently Asked Questions

What is the lazy-eager validation pattern?
It validates a field on blur for the first interaction, then switches to validate-on-change after the first error. This avoids nagging users while they are still typing, then gives immediate feedback once they are actively correcting a mistake.
How does this handle accessibility?
Error messages link to fields via `aria-describedby`, and a form-level `role="alert"` summary announces error counts and lets users jump to each problem field. The `[screen_reader]` approach uses ARIA live regions with polite announcements so assistive tech stays informed.
Does it prevent losing form data on accidental navigation?
Yes. It combines a `beforeunload` warning with `[persistence_method]` persistence, restoring entered values on return. This matters most for long multi-step forms, where re-entering everything after an accidental back press is a common source of abandonment.
How are async checks like email uniqueness handled?
Fields listed in `[async_fields]` get debounced asynchronous validation with a loading spinner and cached results. Debouncing avoids a request per keystroke, and caching prevents re-checking the same value, which keeps both the UI responsive and the server load reasonable.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in Frontend Development Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

AI assistant · trained on my work

👋

Hey there!

Quick Actions

WhatsApp Direct line to me

Chat on WhatsApp

+880 1723 741224 · Replies within the hour on working days

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

mejba.13@gmail.com

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support