Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Textbox TextMode="Email" asp.net

Tags:

asp.net

I tried to use text box with text mode="Email", but it only validate is the text with @ or not. I can still pass my text with ABC@ABC without any second level domain.

I still have to validate the string input by another validation/function to done this.

<asp:TextBox ID="Email" MaxLength="50" PlaceHolder="[email protected]" runat="server" textMode="Email" /> =
<br/>
<asp:RegularExpressionValidator ID="EmailFormat" runat="server" Text="Please enter a valid Email" ToolTip="Please enter a valid Email" ControlToValidate="Email" ValidationExpression="(\w)+@(\w)+.com(.(\w)+)*" ForeColor="Red"  />
like image 433
Yu Yenkan Avatar asked Jan 22 '26 07:01

Yu Yenkan


1 Answers

I think you have to try Email Validation using regular expression in ASP.Net. I have below code for you which solve your problem.

<asp:TextBox ID="txtEmailAddress" runat="server" CssClass="NormalTextBox inputText"></asp:TextBox>

<asp:RegularExpressionValidator ID="revEmailAddress" runat="server" SetFocusOnError="true"
                        Display="None" ControlToValidate="txtEmailAddress" resourceKey="revEmailAddress"
                        ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ValidationGroup="register"></asp:RegularExpressionValidator>

<asp:Button ID="lnkBtnRegister" runat="server" ValidationGroup="register"
                        CssClass="login-btn fl" CausesValidation="true" OnClick="lnkBtnRegister_Click" />
<asp:ValidationSummary ID="valsumRegister" resourceKey="valsumRegister" runat="server"
                    ShowSummary="false" ShowMessageBox="true" ValidationGroup="register" HeaderText="Please Provide..." />
like image 178
Keval Gangani Avatar answered Jan 23 '26 20:01

Keval Gangani