//将您的数字字符串带进去就可以了。
private bool IsNum(String sNum)
{
 int isDec = 0;
 for(int i=0;i<sNum.Length;i++)
 {
  if(sNum[i]=='.') isDec++;
  if((!char.IsNumber(sNum,i) && sNum[i]!='.')|| isDec>1) return false;
 }
 return true;
}

解决方案 »

  1.   

    以下的方法是: super76(瞻云听雨) 提供的。他用的是正则表达式。
    //包含小数的数值验证
    public bool IsValidNumric(string numberString)
    {
    Regex rCode = new Regex("^[+-]?\\d+(\\.\\d+)?$");
    if(!rCode.IsMatch(numberString))
    {
    return false;
    }
    else
    {
    return true;
    }
    }
    //整数或纯数字的验证
    public bool IsNumric(string numberString)
    {
    Regex rCode = new Regex("^[+-]?\\d+(\\d+)?$");
    if(!rCode.IsMatch(numberString))
    {
    return false;
    }
    else
    {
    return true;
    }
    }
      

  2.   

    你可以用正侧表达式作阿
    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);
      }
      

  3.   

    我这有个只验证int的
    public bool ifnumber(string str)
    {
    try
    {
    int i=Convert.ToInt32(str);

    }
    catch
    {
    return false;
    }
    if(str.Length>5)
    return false;
    return true; }
      

  4.   

    用正则表达式
    Regex("^[+-]?\\d+(\\.\\d+)?$");
      

  5.   

    用正则
    Regex reg = new Regex(@"^\d+.?\d*$");
    reg.IsMatch(string);
      

  6.   

    public bool IsNum(string str)
    {
    try
    {
    Convert.ToInt32(str.Trim());
    return true;
    }
    catch
    {
    return false;
    }
    }