1

I want to check that client write integer in my textbox so I write my code like this :

<td class="style2">
 <asp:TextBox ID="phonetxt" runat="server" Height="22px" MaxLength="10" 
 Width="158px"></asp:TextBox>
</td>
<td>
 <asp:RequiredFieldValidator ID="PhoneRequiredFieldValidator" runat="server" ForeColor="Red" ControlToValidate="phonetxt"  ErrorMessage="...."></asp:RequiredFieldValidator>
 <asp:RegularExpressionValidator ID="RegularExpressionValidator6" runat="server" Display="None" ErrorMessage="Accepts only numbers." ControlToValidate="phonetxt" ValidationExpression=""^[0-9]*$" Text="*"></asp:RegularExpressionValidator>
</td>

But an error occured like this:

Server Error in '/' Application.
Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: The server tag is not well formed.
Source Error: Line 153: Line 154: Line 155: Line 156: Line 157:

Source File: /account.aspx Line: 155

What shold I do now? Is there any better way for check that?

2 Answers 2

1

Replace

ValidationExpression=""^[0-9]*$"

with

ValidationExpression="^[0-9]*$"
Sign up to request clarification or add additional context in comments.

2 Comments

thanks it's working now but it doesn't show any error when I write wrong values!!!! What's the problem?
a " needs to be escaped within text - so you need to write \"
0

Base on the error. You forget a opening in this

asp:RequiredFieldValidator ID="PhoneRequiredFieldValidator" runat="server" ForeColor="Red" ControlToValidate="phonetxt"  ErrorMessage="...."></asp:RequiredFieldValidator>

< you are missing this...

As for the ValidationExpression=""^[0-9]*$"
If you really need to have " put an escape on it so it become

ValidationExpression="\"^[0-9]*$"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.