Click here to Skip to main content
12,949,601 members (65,517 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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+$

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

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
OriginalGriff 5,489
CHill60 3,380
Maciej Los 2,913
Jochen Arndt 1,935
ppolymorphe 1,820

Advertise | Privacy | Mobile
Web02 | 2.8.170524.1 | Last Updated 16 May 2011
Copyright © CodeProject, 1999-2017
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