How to validate corporate or business email address in asp.net - Free Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server,WCF,Entity framework snippets and tutorial

How to validate corporate or business email address in asp.net

In this article I am going to explain how to validate corporate or business email address in asp.net using RegularExpression.

How to validate corporate or business email address in asp.net


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.



What do you think about this article?

If you found this article useful, please share and follow on Facebook, Twitter, Google Plus and other social media websites. To get free updates subscribe to newsletter. Please put your thoughts and feedback in comments section.

Share this

Share on FacebookTweet on TwitterPlus on Google+


EmoticonEmoticon