# Design input validation rules for my app

Consistent validation rules for every input across client, server, and database, with security checks, error messages, and tests.

- Topic: Software Development
- Framework: RTF
- Level: Standard
- Tags: Coding, Code, Fill-in Template
- Source: https://www.thinkwithprompt.com/prompts/design-input-validation-rules-for-my-app

## Prompt

```text
Help me design input validation for my application.

**Tech stack:** [frontend, backend language/framework, database]
**Where data comes in:** [forms, API endpoints, file uploads, webhooks, imports]
**Data model or fields:** [PASTE schema, types, or the form/endpoint definitions]
**Business rules:** [e.g. "end date after start date", "quantity 1-100", "unique email per account"]
**Current validation code (optional):** [PASTE]

Design validation in layers:
1. **Rules table** - columns: field, type, required, format/pattern, length or range, allowed values, cross-field rules, normalization (trim, case, Unicode), error message for users.
2. **Where each rule lives** - client (for fast feedback only), server (the source of truth), database (constraints: NOT NULL, CHECK, UNIQUE, foreign keys). Show how to share one schema between layers where the stack allows.
3. **Security checks** - allow-lists over block-lists, parameterized queries (never string-built SQL), output encoding against XSS, file upload checks (type by content, size, name), limits on payload size and array lengths, mass-assignment protection.
4. **Error handling** - consistent error response format, field-level messages, no leaking of internal details.
5. **Edge cases to test** - empty, whitespace, very long, Unicode and emoji, negative and zero, boundaries, wrong types, duplicates, concurrent submissions.
6. **Example code** in my stack for one form or endpoint, plus unit tests for its rules.

Flag any business rule that is ambiguous instead of guessing.
```

## What to fill in

- frontend, backend language/framework, database
- forms, API endpoints, file uploads, webhooks, imports
- PASTE schema, types, or the form/endpoint definitions
- PASTE

Free to copy and use. From ThinkWithPrompt (https://www.thinkwithprompt.com/), a library of 2,663 curated AI prompts.
