Only allow two digits after decimal in textbox?

后端 未结 7 918
萌比男神i
萌比男神i 2020-12-10 18:54

I have a textbox where the user enters a number, but how can i make it so that if they type the \'.\' after it it only allows 2 decimal places?

private void          


        
7条回答
  •  北海茫月
    2020-12-10 19:54

    Just add:

    if (Regex.IsMatch(textBox1.Text, @"\.\d\d")) {
       e.Handled = true;
    }
    

    to the end of your function

提交回复
热议问题