Validation Error Messages
You'll learn how to write error messages that help users fix invalid form input quickly and confidently.
What Makes Validation Messages Helpful
When a user submits a form with invalid data, a vague error like "Invalid input" leaves them guessing. Good validation messages work like a helpful coach—they point to the exact problem and suggest how to fix it. Instead of "Error in email field," say "Email must include an @ symbol (e.g., user@example.com)."
Core Principles
Be specific about what's wrong. If a password is too short, don't just say "Invalid password." Say "Password must be at least 8 characters long."
Guide toward a solution. Tell users how to fix it: "Username can only contain letters, numbers, and underscores" is actionable; "Invalid username" is not.
Use plain language. Avoid technical jargon. Instead of "String length validation failed," say "This field cannot be empty."
Show the rule, not just the failure. "Must be between 5-20 characters" teaches users the constraint so they can self-correct.
Message Examples
-
❌ "Invalid date"
✅ "Date must be in MM/DD/YYYY format (e.g., 12/31/2023)" -
❌ "Field required"
✅ "Please enter your full name" -
❌ "Wrong input"
✅ "Phone number must be 10 digits (e.g., 555-123-4567)"
When to Show Messages
Display validation messages after the user has interacted with a field (on blur) or attempted submission—not while they're still typing. This prevents frustration from premature criticism.
Key Takeaway: Validation messages should clearly identify what's wrong, explain the requirement, and ideally show an example—turning errors into learning moments that help users succeed on their next attempt.