c#文本框 写一个字符串判断函数吧,检索字符串中的每一个字符,若ascii码不属于0-9就报错 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private void txtTest_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != 13) //按下的键不是0-9也不是退格和回车 { //do nothing e.Handled = true; }} 正则也行啊if(!Regex.match(textbox1.text,"^[0-9]+$").Success) 正则string pattern="^[0-9]+$"; Int32 j;if (Int32.TryParse(textBox1.Text,out j)){ // textBox1.Text 可轉為 Int32}else{ // textBox1.Text 無法轉為 Int32}if (i == j){} public static bool IsPhone(string input) { string pattern = @"^[0-9]+$"; Regex regex = new Regex(pattern); return regex.IsMatch(input); } 使用验证控件RegularExpressionValidator控件 呜呜呜我还是弄不上啊,我的那个文本框叫txttel在if 里面怎么写啊 ?用这个的时候提示没有Regex,这个还要先定义?if(!Regex.match(textbox1.text,"^[0-9]+$").Success) private void txtPageIndex_KeyPress(object sender, KeyPressEventArgs e) { if (!(Char.IsNumber(e.KeyChar) || e.KeyChar == (char)Keys.Back || e.KeyChar == (char)Keys.Enter)) { e.Handled = true; // 只允许数字键 回格 和 回车 } } 关于OPC的问题 C# 如何往socket写入Unicode编码不可见字符 用C#做校园网登陆软件 C# 语法问题,高手赐教! C#、Matlab高手进呀! 类如何调用当前窗体上的方法? 关于IssueVision下的代理 .Net中添加代码注释的工具(有些问题我没有能解决,欢迎大家讨论,指点一二) 要做信息检索的论文!不知道VFP.NET是什么? 数组里面70%的概率元素值为1,其他的为0,程序怎么写呢? 求修改方法:输入报错为(数组长度大于此表中的列数) 问题如下图,哪种写法好?
private void txtTest_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != 13) //按下的键不是0-9也不是退格和回车
{
//do nothing
e.Handled = true;
}
}
if (Int32.TryParse(textBox1.Text,out j))
{
// textBox1.Text 可轉為 Int32
}
else
{
// textBox1.Text 無法轉為 Int32
}if (i == j)
{}
{
string pattern = @"^[0-9]+$";
Regex regex = new Regex(pattern);
return regex.IsMatch(input);
}
用这个的时候提示没有Regex,这个还要先定义?if(!Regex.match(textbox1.text,"^[0-9]+$").Success)
private void txtPageIndex_KeyPress(object sender, KeyPressEventArgs e)
{ if (!(Char.IsNumber(e.KeyChar) || e.KeyChar == (char)Keys.Back || e.KeyChar == (char)Keys.Enter))
{
e.Handled = true; // 只允许数字键 回格 和 回车
}
}