• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1277
  • Last Modified:

non numeric validation control in asp.net 2.0 C#

I am try to create a validation control that will throw an error when the user trying to enter non-numeric value to the textbox. How can I do this in C#?
0
jung1975
Asked:
jung1975
  • 3
  • 3
1 Solution
 
naveenkohliCommented:
Use regular expression validator that only allows numeric content.

regular expression for that validator will be

"^[0-9]*$"
0
 
jung1975Author Commented:
Ok, I changed my code to like below, but It always show the error message no matter what I type ( number or character). I only want to show the error message if the user enter non-numberic character . Wha I am doing wrong?
             

             <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Non-Numeric Value" ControlToValidate="TextBox12" ValidationExpression="^[0-9]*$"></asp:RegularExpressionValidator></td>
0
 
naveenkohliCommented:
I have same code in my page and it works fine.
Can you show me the related text box tag?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
jung1975Author Commented:
I am sorry. I forgot to metion that I want to be able to accpet the decimal as well. right now, if I enter 2.25, it throws me an error because of the '.'. how can I get around this?
0
 
naveenkohliCommented:
Try this..

"^[0-9]*[.]{0,1}[0-9]*$"
0
 
jung1975Author Commented:
thanks. it works
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now