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.
Some of my previous articles are as follows: Convert
DataTable To JSON Object/Data In ASp.Net Using C#.Net, Show
Loading While Page Loads Using jQuery in Asp.net, Display
Latitude and Longitude Value on Google Map from Sql Server Data Base in Asp.net
Using C#.Net, Credit
Card Data Format Validation Using jQuery In Asp.Net, Enable
and Disable Asp.Net FileUpload Control Using JavaScript, Enable
and Disable Asp.Net FileUpload Control Using jQuery, How
to Enable or Disable Requiredfieldvalidator in Asp.Net Using jQuery, Dynamically
Display Images From Folder By Ajax Using jQuery In Asp.net ,C#, Error
In Visual Studio 2013: WebForms UnobtrusiveValidationMode requires a
ScriptResourceMapping for 'jquery'.
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.
0 comments:
Please let me know your view