How can I restrict the textbox to display 2 digits after the decimal point?

how can I limit the textbox to display 2 digits after the decimal point?

123.22 - true

1000000.123 - false

0.002 - false

3.32 - true

12a.34 - false

Thanks in advance

0


a source to share


3 answers


You can use the NumericUpDown control and set the DecimalPlaces property to 2. This will allow the user to enter more than two decimal places, but when they leave it, it will round their input up or down.



+3


a source


Could you explain more. You want to create a masked text box or check for an existing value in the text box. If you want to create a mask, you can use MaskedTextBox.



+2


a source


Assuming you are using a webform, you can add a regex check on the Validate event to check if the data is in the correct format, something like

^[0-9]*\.[0-9]{2}$

      

must do the trick.

Of course, you can do this on web forms using expression validation.

+1


a source







All Articles