Binary Bits

Bits & Pieces By Kannan

ASP.NET E-Mail Validation With Regular Expression Validator Using The Right Validation Expression

October 02
by Kannan 2. October 2008 12:15

ASP.NET comes with validation controls with which we can validate input values.

One of the most common situation is validating e-mail address. Some of the web sites online provide a Validation Expression which sometimes misses out the top level domain part.

The following is the Validation Expression which I found to be working perfectly.

<asp:TextBox ID="txtUserEmail" runat="server" />
<asp:RequiredFieldValidator ID="rfvUserEmail" runat="server" ControlToValidate="txtUserEmail" ErrorMessage="*"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="rfvUserEmailValidate" runat="server" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ControlToValidate="txtUserEmail" ErrorMessage="Invalid Email Format"></asp:RegularExpressionValidator>
Note: I have added RequiredFieldValidator as RegularExpressionValidator check only for the format

Comments

Add comment


 

biuquote
  • Comment
  • Preview
Loading