Click here to Skip to main content
12,350,728 members (23,976 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP.NET
please any one provide me the c# code for numeric validation.
Posted 16-May-11 3:25am
Pratik Bhesaniya 16-May-11 9:30am
What kind of validation you want ?
Programm3r 16-May-11 9:35am
You'll have to be more specific!
S Mewara 16-May-11 10:26am
No effort
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

int i;
if (!Int.TryParse(myStringToValidate, out i))
   // Failed validation
Manfred R. Bihy 16-May-11 9:41am
I was going to post something along the lines. :) 5+
SAKryukov 16-May-11 21:08pm
As simple as that, my 5.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


If it's number validation that your referring to, when have a look at the following blog post: Numeric validation in Textbox using regular expressions

From the blog post:

Only numbers can enter into that Textbox
We can use Regular expression validator for this:
Assign the following value to the validation expression property: ^\d+$

<asp:TextBox ID="TextBox1" runat="server" Style="z-index: 100; left: 259px; position: absolute;
top: 283px" ValidationGroup="check">
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBox1"
ErrorMessage="Please Enter Only Numbers" Style="z-index: 101; left: 424px; position: absolute;
top: 285px" ValidationExpression="^\d+$" ValidationGroup="check">

Kind regards,

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 16 May 2011
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100