Click here to Skip to main content
12,454,477 members (56,098 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
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 21-Jan-13 23:56pm
Comments
Gittu 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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

private void textBox1_TextChanged(object sender, EventArgs e)
       {
           if (Convert.ToInt32(textBox1.Text.Trim()).Equals(0))
           {
               this.textBox1.Text = Convert.ToString(0) ;
           }
       }
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160826.1 | Last Updated 22 Jan 2013
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