Click here to Skip to main content
Rate this: bad
good
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
Comments
Pratik Bhesaniya at 16-May-11 9:30am
   
What kind of validation you want ?
Programm3r at 16-May-11 9:35am
   
You'll have to be more specific!
S Mewara at 16-May-11 10:26am
   
No effort
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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

Solution 2

Hi,
 
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,
  Permalink  
v3

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

  Print Answers RSS
0 OriginalGriff 7,280
1 Sergey Alexandrovich Kryukov 6,059
2 Maciej Los 3,579
3 Peter Leow 3,383
4 CHill60 2,522


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 16 May 2011
Copyright © CodeProject, 1999-2014
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