Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I m using Regular expression in text box to accept only number but when i enter characters It is displaying the message "Enter only no " but when I click on update the character get saved in database.

I m using the following code

XML
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"

                    ValidationExpression="(^[-]?[1-9]\d+$)|(^[-]?[1-9]$)|(^0$)|(^[-]?[1-9]\d+\.\d$)|(^[-]?[0-9]\.\d$)" ControlToValidate="txtcontactno"
                     ErrorMessage="Enter Number Only!" ForeColor="White"
                    ValidationGroup="check" Font-Size="Small" Display="Dynamic"></asp:RegularExpressionValidator>
Posted

1 solution

Make sure the textbox also has it's ValidationGroup set to "check" to make sure it validates on postback. Also make sure the textbox has CausesValidation set to true.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900