你好,
TextBox的InputScope="Number"只是可以呼出数字键盘,对于输入范围不进行任何验证,更多信息可以看看
TextBox 的描述。
如果要验证,只能是在TextChanged事件里处理了,方法有很多,可以参考下面的Code:
private void txtNeumeric_TextChanged(object sender, EventArgs e)
{
if (System.Text.RegularExpressions.Regex.IsMatch(txtNo.Text, "^[0-9 ]+$") || txtNo.Text == "")
{
//do something
}
else
{
txtNo.Text = txtNo.Text.Remove(txtNo.Text.Length - 1, 1);
this.txtNo.SelectionStart = this.txtNo.TextLength + 1;
MessageBox.Show("Enter only Numeric");
}
}
--Simon
True mastery of any skill takes a lifetime.