---
title: "RegularExpressionValidator Control in ASP.Net"  
description: "Using RegularExpressionValidator server control, you can check a user's input based on a pattern that you define using a regular expression. This mean"  
author: "Pushpendra Singh"  
published: 2010-11-10  
updated: 2020-03-04  
canonical: https://www.mindstick.com/articles/197/regularexpressionvalidator-control-in-asp-dot-net  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 2 minutes  

---

# RegularExpressionValidator Control in ASP.Net

Using RegularExpressionValidator server control, you can check a user's input based on a pattern that you define using a [regular expression](https://www.mindstick.com/forum/65/regular-expression). This means that you can define a [structure](https://www.mindstick.com/forum/1188/how-to-create-structure-in-c) that a user's input will be applied against to see if its structure matches the one that you define.\

```
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="RegularExpressionValidator"></asp:RegularExpressionValidator>
```

The RegularExpressionValidator control is used to ensure that an input value matches a specified pattern.

The validation will not fail if the input control is empty. Use the RequiredFieldValidator control to make the field required.

**[Properties](https://yourviews.mindstick.com/view/81845/now-it-s-possible-to-predict-properties-of-any-molecule):**

| ControlToValidate | The id of the control to validate |
| --- | --- |
| [Error Message](https://www.mindstick.com/forum/23174/error-message-the-page-you-are-requesting-cannot-be-served-because-of-the-extension-configuration) | The text to display in the page when [validation fails](https://www.mindstick.com/forum/34291/how-to-raise-a-callback-when-asp-dot-net-mvc-client-validation-fails). Note: This text will also be displayed in the validation control if the [Text property](https://www.mindstick.com/forum/161/problem-in-getting-text-property-for-sender-object) is not set |
| Validation Expression | Specifies the expression used to [validate input](https://www.mindstick.com/forum/158278/how-to-use-the-pattern-attribute-to-validate-input-fields-against-a-specific-regular-expression) control. |

**Code:**

```
<asp:Label ID="Label1" runat="server" Text="email id"></asp:Label><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="enter a valid email id" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>  <asp:Button ID="Button1" runat="server" Text="Submit" />
```

When we enter invalid email id then error message will show

![RegularExpressionValidator Control in ASP.Net](https://www.mindstick.com/mindstickarticle/46ad6aee-13e6-4aad-a24a-268d20467f9f/images/9e0ef314-775b-418f-b25d-f270eb3530d4.png)

When we enter valid email id then page will execute

![RegularExpressionValidator Control in ASP.Net](https://www.mindstick.com/mindstickarticle/46ad6aee-13e6-4aad-a24a-268d20467f9f/images/2a886176-ef62-40c2-ac29-c59818680207.png)

---

Original Source: https://www.mindstick.com/articles/197/regularexpressionvalidator-control-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
