我只想textbox中输入数字其他都不可以输入请哪位大侠指点。谢谢 string s = textBox1.Text;
double d = Double.Parse(s);
double sq = d * d;
// if
//(s = ("")) label1.Text = d + "的平方是:" + sq;
// else
MessageBox.Show("");
double d = Double.Parse(s);
double sq = d * d;
// if
//(s = ("")) label1.Text = d + "的平方是:" + sq;
// else
MessageBox.Show("");
{
base.OnKeyPress(e); if ((int)e.KeyChar <= 32) // 特殊键(含空格), 不处理
{
return;
} if (!char.IsDigit(e.KeyChar)) // 非数字键, 放弃该输入
{
e.Handled = true;
return;
}
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
//屏蔽 组合键
if ((e.KeyChar == 3) || (e.KeyChar == 24) || (e.KeyChar == 26))
{
return;
} //只允许数字
if ("0123456789".IndexOf(e.KeyChar.ToString()) == -1)
{
e.Handled = true;
return;
}
}
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8))
e.Handled = true;
base.OnKeyPress(e);
}
# function isWrongNumber(s)
# {
# if (s.length > 0)
# {
# var re = /^[0-9]*(\d*)?$/;
# if (!re.test(s)) {
# alert("请输入正确的天数!");
# return false;
# }
# } else {
# alert("请填写天数!");
# return false;
# }
# return true;
# }
Match ma = reg.Match(this.textBox1.Text.Text);
if (ma.Success)
{
return;
}
else
{
Response.Write("<script>alert('请输入数字')</script>");
return;
}
WinFrom的话用KeyPress楼上都可参考!
忘了写了,除了屏蔽ctrl+v,还要屏蔽右键,里面有粘贴菜单.现在觉得最好写到change事件里.