Aug 31, 2010

How to validate Numeric Decimal Values using c#

Decimal validation mostly used utility in the software application ..........

The Below sample code is done the numeric validation exactly.it doesn't allow the double dot in numeric values...........


private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
NumericDecimalValidation(sender,e);
}

public void NumericDecimalValidation(object Sender, KeyPressEventArgs e)
{

if (char.IsDigit(e.KeyChar) || e.KeyChar.ToString() == "." || char.IsControl(e.KeyChar))
{
if (((TextBox)Sender).Text.IndexOf(".") != -1 && e.KeyChar.ToString() == ".")
e.Handled = true;
else
e.Handled = false;
}
else
e.Handled = true;
}

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More