Make field email validate and required

kyle_13 picture kyle_13 · Jun 17, 2013 · Viewed 13.5k times · Source

I need to have a textbox be validated as an email address, and make it a required field. I also need to restrict the email addresses to a specific domain name only (e.g. @example.com).

<asp:TextBox ID="EmailTextBox" runat="server" Text='<%# Bind("Email") %>' 
                                    MaxLength="50" />

What is the best approach to this?

Answer

Romil picture Romil · Nov 1, 2014

It would work better if you add

ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"

instead of

ValidationExpression="^\w+([-+.']\w+)*@domain.com$" 

in the code above