第一种:
很常见一个字符去判断是否為數字。
第二種:
用正則表邊式
using System.Text.RegularExpressions;
Regex reg=new Regex(@"^\d+(\.\d+)?$",RegexOptions.None);
// Match the double data
if(!reg.IsMatch(this.txtRefWeight.Text) || !reg.IsMatch(this.txtWeiRange.Text))
{
labelStatus.Text="重量格式錯誤!";
labelStatus.ForeColor=Color.Red;
this.btnupload.Enabled=false;
return;
}
第三種:
是最笨也最慢的方法就是用铺抓異常
try{
this.Weight=Convert.ToDouble(this.txtRefWeight.Text);//Set the Weight
this.Weight_range=Convert.ToDouble(this.txtWeiRange.Text);
}catch
{
labelStatus.Text="重量格式錯誤!";
labelStatus.ForeColor=Color.Red;
this.btnupload.Enabled=false;
return;
}
评论
liuzhenyu170 2008-07-28
受教了!谢谢楼主
发表评论

提醒: 该博客已发表在公共论坛,博客所有留言会成为论坛回贴,留言请注意遵守论坛发贴规则

您还没有登录,请登录后发表评论

心似海
搜索本博客
博客分类
最近加入圈子
存档
最新评论