# Input Validation

> Making sure what users send fits the rules. Then your code uses it.

**Field:** Software Development  
**Category:** Security  
**Also known as:** Validation, Validating Input, Data Validation

## Think of it like

Think of it like a bouncer checking tickets. Only the right kind of thing gets through the door.

## Definition

Input validation checks outside data against rules before your code uses it. An age should be a whole number between 0 and 150. An email should look like an email. Anything that breaks the rules is turned away with a clear message. Checks in the browser are only for comfort; the server must check again, because anyone can skip the page.

## Example

Lucy's sign-up form asks for an age. Someone sends minus 5 straight to her API, and the server answers 400 Bad Request instead of saving it.

## Why it matters

Most attacks start with input the code did not expect. Checking it first stops whole kinds of bug.

## Common mistake

Checking input only in the browser. Anyone can send a request straight to the server, with any data at all.

## Three principles

- **Check before use.** Every outside input.
- **Allow the good.** Not just block the bad.
- **On the server.** Always, every time.

## Related terms

- [SQL Injection](https://learn.benibix.com/term/development/sql-injection)
- [Cross-Site Scripting (XSS)](https://learn.benibix.com/term/development/cross-site-scripting)
- [Security Vulnerability](https://learn.benibix.com/term/development/vulnerability)
- [HTTP Status Code](https://learn.benibix.com/term/infrastructure/http-status-code)
- [Injection Attack](https://learn.benibix.com/term/development/injection-attack)
- [HTML Input Element](https://learn.benibix.com/term/development/html-input-element)

## Told apart from

- [Input Validation vs Parameterized Query](https://learn.benibix.com/compare/input-validation-vs-parameterized-query): People think checking what users type is enough to stop SQL injection, and it is not. Input validation turns away data that has the wrong shape, like letters in an age box. But a name can still hold a quote. A parameterized query keeps every value apart from the command, so even odd text stays data. You want both.
- [Input Validation vs Output Encoding](https://learn.benibix.com/compare/input-validation-vs-output-encoding): People think checking what users type stops cross-site scripting, and it does not. Input validation turns away data with the wrong shape as it comes in. But a comment box has to take almost any text. Output encoding works on the way out. It turns signs like the less-than sign into safe codes, so the browser shows the text and never runs it. You want both.

## Taught in

- [Regular Expressions (Regex)](https://learn.benibix.com/learn/development-formats/regular-expressions-regex): File Formats, 11/11

---

Source: https://learn.benibix.com/term/development/input-validation
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
