Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my project i am using a textbox for entering the Price of an item.I need to give a validation for the value like 00000, that means more than one zero shouldn't accept..
which validation control i can use for this.please help me to find it.
Posted
Comments
P_Dash 22-Jan-13 6:09am    
Well as per my knowledge there is no specific Validator present for this purpose.
But yes you can use a for loop & check if only 0s present in input and intern restrict it from being processed.
ridoy 22-Jan-13 6:55am    
using regex would be a better option
Logi Guna 22-Jan-13 9:23am    
add these lines on textBox1 TextChanged event
double value;
if (double.TryParse(textBox1.Text, out value) && (value == 0.0)) textBox1.Text = "0";

1 solution

C#
private void textBox1_TextChanged(object sender, EventArgs e)
       {
           if (Convert.ToInt32(textBox1.Text.Trim()).Equals(0))
           {
               this.textBox1.Text = Convert.ToString(0) ;
           }
       }
 
Share this answer
 
v2
Comments
Quirkafleeg 22-Jan-13 9:39am    
Only a 2...
What happens when you type 'a'? A FormatException error.

"Programmers need to learn how stupid customers can be"

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