EnjoySharePoint YouTube Channel

RegularExpressionValidator example in Asp.Net

In this post we will discuss how to use RegularExpressionValidator in Asp.Net. For this example we will see how to validate email id using RegularExpressionValidator in Asp.Net.

Get Office 365 Enterprise E3 Or Business Premium Subscription & Try out all the features

You can also check examples of RangeValidator and RequiredFieldValidator in Asp.Net.

– RegularExpressionValidator: Here validation succeeds if the value in an input control matches a specified regular expression.

Below are the properties:
ControlToValidate: Which control you want to validate.

ErrorMessage: What error message you want to show.

ValidationExpression: This represents the validation expression you want to validate. You can directly set the validation expression or Asp.Net provides some validation expressions which you can select from RegularExpressionValidator’s properties window.

Below is the full HTML code:

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”ValidatorExamples.aspx.cs”
Inherits=”ValidatorExamples” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-

<html xmlns=”http://www.w3.org/1999/xhtml”>
<head runat=”server”>
<title>RegularExpressionValidator example in Asp.Net</title>
<form id=”form1″ runat=”server”>
Enter EmailID:<asp:TextBox ID=”txtEmailID” runat=”server”></asp:TextBox>
<br />
<asp:RegularExpressionValidator ID=”RegularExpressionValidator1″ runat=”server” ForeColor=”Red”
ControlToValidate=”txtEmailID” ErrorMessage=”Please enter a valid email id” ValidationExpression=”\w+([-+.’]\w+)*@

<br />
<asp:Button ID=”btnSubmit” runat=”server” Text=”Submit” />

If a user enters a invalid email id then the error will be shown as shown in the figure below:


Also you can check out my previous posts on:
Check out Best Alternative to InfoPath -> Try Now
You May Also like the Following SharePoint Tutorials:

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →