专注.NET技术及其相关应用开发!

给我一个机会,还你一个惊喜!用这个机会创造出更多的价值!

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
判断输入的是否是数字函數
#region 判断输入的是否是数字函數
 /// <summary>
 /// 名称:IsNumber
 /// 功能:判断输入的是否是数字
 /// 参数:string strNumber:源文本
 /// 返回值: bool true:是 false:否
 
 public class myclass
 {
  /*
   * 判断字符串是否为数字函数,正则表达式
   */
  public bool IsNumber(String strNumber)
  {
   Regex objNotNumberPattern=new Regex("[^0-9.-]");
   Regex objTwoDotPattern=new Regex("[0-9]*[.][0-9]*[.][0-9]*");
   Regex objTwoMinusPattern=new Regex("[0-9]*[-][0-9]*[-][0-9]*");
   String strValidRealPattern="^([-]|[.]|[-.]|[0-9])[0-9]*[.]*[0-9]+$";
   String strValidIntegerPattern="^([-]|[0-9])[0-9]*$";
   Regex objNumberPattern =new Regex("(" + strValidRealPattern +")|(" + strValidIntegerPattern + ")");
   return !objNotNumberPattern.IsMatch(strNumber) &&
    !objTwoDotPattern.IsMatch(strNumber) &&
    !objTwoMinusPattern.IsMatch(strNumber) &&
    objNumberPattern.IsMatch(strNumber);
  }   
 }
 #endregion
posted on 2006-02-18 11:08  婕舞飞扬  阅读(2216)  评论(3编辑  收藏  举报