ASP.Net RegularExpression for Email validation not working

Last Reply one year ago By pandeyism

Posted one year ago

i am trying to update the form.While clicking on update button,i am getting the validation message as invalid email address.

i tried by adding validation expression as 

[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@
(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?

but it dint worked.

emailids are: info@kmkya.kiev.ua and romexpo@romexpo.ro

code: 

<td class="style10"><br/>Email ID <br/>  
    <asp:TextBox ID="txtemail" runat="server" Width="207"></asp:TextBox>    
    <asp:RegularExpressionValidator ID="RegularExpressionValidator3" ValidationGroup="addval" runat="server" ErrorMessage="Invalid email address." ForeColor="Red" 
        ControlToValidate="txtemail" ValidationExpression="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?" ></asp:RegularExpressionValidator>
</td>

what is causing the problem?

Any help will be appreciated.

i am not having problem with other ids. right now only this ids is making the problem.

Posted one year ago Modified on one year ago

Hey chetan,

Please refer below sample it's working.

HTML

<div>
    <asp:TextBox ID="txtemail" runat="server" Width="207"></asp:TextBox>
    <asp:RegularExpressionValidator ID="RegularExpressionValidator3" ValidationGroup="addval"
        runat="server" ErrorMessage="Invalid email address." ForeColor="Red" ControlToValidate="txtemail"
        ValidationExpression="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"></asp:RegularExpressionValidator>
    <asp:Button Text="Update" runat="server" />
</div>

Screenshot