Need a validation code for a textbox in windows form, that allow me to enter the values like
1
11
1.3
1.33
11.33
I am using this text box for entering tax values .
this textbox should allow only two digits before and after decimal point .
Thanks in advance :)

waqas memon141 reputationPosted Jul 20, 2013, 8:04 AM EDT
Pankaj PandeyRank #642 · 3.7K reputationPosted Jul 19, 2013, 5:47 AM EDT
create a function in which split the textbox data by ".".
var x=txtbox.text.Split(".");
string y=x[0].tostring();
string z=x[1].tostring();
now check that if x.lenght>2 or y.length>2 then raise validation.
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 19, 2013, 6:20 AM EDT
Try like this
you need to do this after entering the data in textbox
this.textBox2.Leave += new System.EventHandler(this.textBox1_TextLeave);
Regards,
Iftikar
Ramesh Ushodaya7 reputationPosted Jul 19, 2013, 6:24 AM EDT
I need this validation when key press .
Is it possible ?
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 19, 2013, 6:32 AM EDT
this.textBox1.KeyPress += new KeyPressEventHandler(this.textBox1_KeyPress);
Regards,
Iftikar
Ramesh Ushodaya7 reputationPosted Jul 19, 2013, 11:13 PM EDT
I need this validation when Keypress.
It should work like this
User can allow to enter upto two digits before and after the decimal point.
if user enter two digits it should not allow for the third digit but it can allow ".".
if user enter "." it should allow only two digits after ".".
like 2, 22, 2.3, 2.33, .3, .33, 2.33, 22.33
A Big Thanks for the replies :) .
But need a Perfect solution :( .
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 20, 2013, 12:24 AM EDT
set the mask as 00.00
Regards,
Iftikar
Ramesh Ushodaya7 reputationPosted Jul 23, 2013, 10:49 PM EDT
Thank you so much :)