このコードを使用して入力1小数点のみを許可しています。それは正常に動作します。しかし、小数点以下2桁しか入力できないようにするにはどうすればいいですか?入力を許可する小数点以下2桁(C#+ WindowsPhone)
C#
private void txtPrecio_KeyDown(object sender, KeyEventArgs e)
{
TextBox txt1 = (TextBox)sender;
if (txt1.Text.Contains(".") && e.PlatformKeyCode == 190)
{
e.Handled = true;
}
}
感謝を。私はあなたの例に従って、私はこの正規表現を作成し、うまく動作します:if(Regex.IsMatch(txt1.Text、 "^ \\ d * \\。\\ d {2} $"))e.Handled = true; – aco