---
uid: web-pages/overview/ui-layouts-and-themes/validating-user-input-in-aspnet-web-pages-sites
title: "Validating User Input in ASP.NET Web Pages (Razor) Sites | Microsoft Docs"
author: tfitzmac
description: "This article discusses how to validate information you get from users — that is, to make sure that users enter valid information in HTML forms in an AS..."
ms.author: aspnetcontent
manager: wpickett
ms.date: 02/20/2014
ms.topic: article
ms.assetid: 4eb060cc-cf14-41ae-bab1-14a2c15332d0
ms.technology: dotnet-webpages
ms.prod: .net-framework
msc.legacyurl: /web-pages/overview/ui-layouts-and-themes/validating-user-input-in-aspnet-web-pages-sites
msc.type: authoredcontent
---
Validating User Input in ASP.NET Web Pages (Razor) Sites
====================
by [Tom FitzMacken](https://github.com/tfitzmac)
> This article discusses how to validate information you get from users — that is, to make sure that users enter valid information in HTML forms in an ASP.NET Web Pages (Razor) site.
>
> What you'll learn:
>
> - How to check that a user's input matches validation criteria that you define.
> - How to determine whether all validation tests have passed.
> - How to display validation errors (and how to format them).
> - How to validate data that doesn't come directly from users.
>
> These are the ASP.NET programming concepts introduced in the article:
>
> - The `Validation` helper.
> - The `Html.ValidationSummary` and `Html.ValidationMessage` methods.
>
>
> ## Software versions used in the tutorial
>
>
> - ASP.NET Web Pages (Razor) 3
>
>
> This tutorial also works with ASP.NET Web Pages 2.
This article contains the following sections:
- [Overview of User Input Validation](#Overview_of_User_Input_Validation)
- [Validating User Input](#Validating_User_Input)
- [Adding Client-Side Validation](#Adding_Client-Side_Validation)
- [Formatting Validation Errors](#Formatting_Validation_Errors)
- [Validating Data That Doesn't Come Directly from Users](#Validating_Data_That_Doesnt_Come_Directly_from_Users)
## Overview of User Input Validation
If you ask users to enter information in a page — for example, into a form — it's important to make sure that the values that they enter are valid. For example, you don't want to process a form that's missing critical information.
When users enter values into an HTML form, the values that they enter are strings. In many cases, the values you need are some other data types, like integers or dates. Therefore, you also have to make sure that the values that users enter can be correctly converted to the appropriate data types.
You might also have certain restrictions on the values. Even if users correctly enter an integer, for example, you might need to make sure that the value falls within a certain range.
![Validation errors that use CSS style classes](validating-user-input-in-aspnet-web-pages-sites/_static/image1.png)
> [!NOTE]
>
> **Important** Validating user input is also important for security. When you restrict the values that users can enter in forms, you reduce the chance that someone can enter a value that can compromise the security of your site.
## Validating User Input
In ASP.NET Web Pages 2, you can use the `Validator` helper to test user input. The basic approach is to do the following:
1. Determine which input elements (fields) you want to validate.
You typically validate values in `` elements in a form. However, it's a good practice to validate all input, even input that comes from a constrained element like a `