Sunday, 3 July 2016

Business Email Validation Using RegularExpressionValidator Control in Asp.net

7/03/2016 - By Pranav Singh 0



This article will show you how you can validate the business email validation using regularexpressionvalidator control in asp.net.  In this I have used regulaexpression to validate the business email.


So for this article first we will create a new asp.net application and add textbox, button and regularexpressionvalidator control. After adding all the controls your page will look as shown below.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm7.aspx.cs" Inherits="WebApplication7.WebForm7" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Business Email Validation Using RegularExpressionValidator Control in asp.net</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            Email Id :
            <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
                ErrorMessage="Please enter a valid business email id." ControlToValidate="txtEmail"
                Style="color: #FF0000"
                ValidationExpression="^[a-z0-9](\.?[a-z0-9])([\w-\.]+@(?!yahoo.com)(?!yahoo.in)(?!yahoo.co.in)(?!gmail.com)(?!hotmail.com)(?!inbox.com)(?!outlook.com)(?!rediffmail.com)(?!aol.com)([\w-]+\.)+[\w-]{2,4})?$"></asp:RegularExpressionValidator>
            <br />
            <asp:Button ID="Button1" runat="server" Text="Validate" />
        </div>
    </form>
</body>
</html>

Now in above code please check the highlighted part of the code. In validation expression I have used a regex to validate the email.

^[a-z0-9](\.?[a-z0-9])([\w-\.]+@(?!yahoo.com)(?!yahoo.in)(?!yahoo.co.in)(?!gmail.com)(?!hotmail.com)(?!inbox.com)(?!outlook.com)(?!rediffmail.com)(?!aol.com)([\w-]+\.)+[\w-]{2,4})?$

In above we just need to define the domain of email provider which we want to eliminate like gmail.com, yahoo.com etc.

Now we have done run the application to check the output.

About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top