浏览 408 次
|
精华帖 (0) :: 良好帖 (0) :: 新手帖 (1) :: 隐藏帖 (0)
|
|
|---|---|
| 作者 | 正文 |
|
最后更新时间:2008-04-03
第一种:
很常见一个字符去判断是否為數字。 第二種: 用正則表邊式 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; } 声明:JavaEye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
|
| 返回顶楼 | |
|
最后更新时间:2008-07-28
受教了!谢谢楼主
|
|
| 返回顶楼 | |



