• Introduction:
  • In this tutorial we will learn how to use RegularExpressionValidator in asp.net or what is RegularExpressionValidator in asp.net or why RegularExpressionValidator in asp.net with example.
  • Description:

The RegularExpressionValidator used to validating the input text with matching a pattern of a

regular expression. Such as Email Address, Phone Number, Pin Code etc. 


Let’s see a small example of RegularExpressionValidator:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RegularExpressionValidator.aspx.cs"
Inherits="AspDotNet.RegularExpressionValidator" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
   <form id="form1" runat="server">
        Enter Mobile No:<br />
    <asp:TextBox runat="server" id="txtmobile" /><br />
<asp:RegularExpressionValidator runat="server" style="color:red;"
    id="rexmob" controltovalidate="txtmobile"  validationexpression="[0-9]{10}"
    errormessage="Please enter a 10 digit Mobile number!" />
<br />
<br />


In above code we validate Mobile Number. When we entered 10 digit number then its valid but if we entered 9 digit or 11 digit then it give error message of invalid number.  



How to use RegularExpressionValidator in Asp.Net

I hope this article will help to you.

Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like