How to check decimal places from TextBox input?

  • Thread starter Thread starter pedestrian via DotNetMonster.com
  • Start date Start date
P

pedestrian via DotNetMonster.com

Says I have a TextBox which accept money values. (Assume I cast the input
into Decimal data type), how to check whether user is enter 2 decimal places
(valid)
or more than 2 decimal places (invalid input for money values)?

Thanks for replying...
 
Find the decimal character and then just count the characters that comes
after. Something like this:

int index =
textBox.Text.IndexOf(NumberFormatInfo.CurrentInfo.CurrencyDecimalSeparator);
int count = textBox.Text.SubString(index + 1).Length;

/claes
 
Thanks for valuable answer, Claes...
I shall try it....

Regards
 
Back
Top