如何判断一个文本中的输入数据是合法的整形或浮点型 using System.Text.RegularExpressions; 正则表达式... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 正则表达式是一种,也可应用TRY,CATCH来强制转换,如果catch到错误,自然不合法。 限制用户输入数字:using System.Text.RegularExpressions; ......string str;......bool yn=Regex.IsMatch(str,@"^[0-9]+$");if(yn==true) { MessageBox.Show("y"); //含有数字}else{ MessageBox.Show("n"); //不含有数字} 或者try{double.Parse(txtNN.Text)} i am used to use try-catch, thank you all.Check out now. public class NumInputBox :System.Windows.Forms.TextBox{ public NumInputBox() { this.ImeMode = System.Windows.Forms.ImeMode.Disable; } protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e) { if(Char.IsDigit(e.KeyChar)||(e.KeyChar==(char)0x08)) { base.OnKeyPress(e); } else { e.Handled = true; } }} .abc 后缀的文件是什么文件/格式?,把内容复制到.txt文本后变小。(1000字节变成了998字节) c#下数据库问题 请教如何生成图片 listview与XML问题 关于接口的提问 求一超简单的正则表达式 TREEVIEW节点的双击事件问题? 关于事件 怎样安全地存储数据IP/用户名/密码等配置信息? 利用 AForge.NET如何两路摄像头的保存图片,我只能保存一路 树型控件问题,在线等待 请问?功能象net send命令?
也可应用TRY,CATCH来强制转换,如果catch到错误,自然不合法。
限制用户输入数字:using System.Text.RegularExpressions; ......string str;......bool yn=Regex.IsMatch(str,@"^[0-9]+$");
if(yn==true)
{ MessageBox.Show("y"); //含有数字
}
else
{
MessageBox.Show("n"); //不含有数字}
try{double.Parse(txtNN.Text)}
Check out now.
{
public NumInputBox()
{
this.ImeMode = System.Windows.Forms.ImeMode.Disable;
}
protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e)
{
if(Char.IsDigit(e.KeyChar)||(e.KeyChar==(char)0x08))
{
base.OnKeyPress(e);
}
else
{
e.Handled = true;
}
}
}