In
this article I am going to explain how to validate corporate or business email
address in asp.net using RegularExpression.
In
the previous article I have explained how to show and hide the password oncheckbox click using Jquery in asp.net, how to get month calendar with week dayname in sql server, how to get the current month name with number of days inSql server and how to get the number of days in current month in Sql server.
Description:
Recently
I have got a requirement, only business or corporate email address need to be entered.
So I have to validate the free email address like Gmail, yahoo, Rediff, hotmail
etc.
Implementation:
I
have used the Regular expression validator control to validate. Add the below
given code:
ValidationExpression="^[a-z0-9](\.?[a-z0-9])([\w-\.]+@(?!gmail.com)(?!yahoo.com)(?!hotmail.com)(?!rediffmail.com)(?!outlook.com)(?!zoho.com)([\w-]+\.)+[\w-]{2,4})?$"
Example:
Add
a webform to project. Drag and drop the textbox and Regularexpressionvalidator
from toolbox to webform
Complete
HTML Markup of Webform:
<fieldset style="width:50%">
<legend>validate
corporate email address </legend>
<table>
<tr><td>Enter Email :</td><td>
<asp:TextBox ID="txtemail" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ErrorMessage="Please
Enter Bussnies Email Id"
ValidationExpression="^[a-z0-9](\.?[a-z0-9])([\w-\.]+@(?!gmail.com)(?!yahoo.com)(?!hotmail.com)(?!rediffmail.com)(?!outlook.com)(?!zoho.com)([\w-]+\.)+[\w-]{2,4})?$"
ControlToValidate="txtemail" ForeColor="#FF3300"></asp:RegularExpressionValidator></td></tr>
<tr><td></td><td>
</td></tr>
</table>
</fieldset>
Now
run the project and test it.
No comments:
Post a Comment