Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
please any one provide me the c# code for numeric validation.
Posted
Comments
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!
Sandeep Mewara 16-May-11 10:26am    
No effort

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,
 
Share this answer
 
v3
Try:
int i;
if (!Int.TryParse(myStringToValidate, out i))
   {
   // Failed validation
   }
 
Share this answer
 
Comments
Manfred Rudolf Bihy 16-May-11 9:41am    
I was going to post something along the lines. :) 5+
Sergey Alexandrovich Kryukov 16-May-11 21:08pm    
As simple as that, my 5.
--SA

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