ASP.Net RegularExpression for Email validation not working

Last Reply 5 months ago By pandeyism

Posted 5 months 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.

You are viewing reply posted by: pandeyism 5 months ago.
Posted 5 months ago Modified on 5 months 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