How to protect the to validate email address to gmail.com using regular expression in asp.net

In this article, we will protect to email address from gmail .com. in this we can enter all email address instead of gmail.com. In this example, we are used asp.net validation control to validate this. We have just use the regular expression validator , we can just write this below code to validate :-

ValidationExpression="^([\w-\.]+@(?!gmail.com)([\w-]+\.)+[\w-]{2,4})?$">

Design:-


Source code:-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="emailvalidation.aspx.cs"
    Inherits="emailvalidation" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">


    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <fieldset style="width: 600px">
            <legend><strong>Protect email address for gmail.com </strong></legend>
            <br />
            <strong>Email Address</strong>
            <asp:TextBox ID="txtemail" runat="server" Width="200px"></asp:TextBox>
            <asp:RegularExpressionValidator ID="REVemail" runat="server"
                ControlToValidate="txtemail" Display="Dynamic"
                ErrorMessage="Please enter the valid email" ForeColor="Red"
               
                ValidationExpression="^([\w-\.]+@(?!gmail.com)([\w-]+\.)+[\w-]{2,4})?$"></asp:RegularExpressionValidator>
        </fieldset>
    </div>
    </form>
</body>
</html>


 Out-Put:-


How to protect the to validate email address to gmail.com using regular expression in asp.net How to protect the to validate email address to gmail.com using regular expression in asp.net Reviewed by NEERAJ SRIVASTAVA on 9:39:00 AM Rating: 5

1 comment:

  1. fado place items in the shopping ecommerce system of Amazon. Reputable service, fast, secure, is and has been widely used and very satisfied with our services.

    ReplyDelete

Powered by Blogger.