验证textbox输入的是否是数字,包括小数

public bool isnumeric(string str)
        {
            int count = 0;
            if (str.Trim() == "" || str.Trim().Length == 0)
            {
                return false;
            }
            else
            {
                char[] ch = new char[str.Length];
                ch = str.ToCharArray();
                for (int i = 0; i < ch.Length; i++)
                {
                    if (!char.IsNumber(ch[i]) && ch[i] != '.')
                    {
                        return false;
                    }
                    if (ch[i]=='.')
                    {
                        count++;
                        if (i == 0 || i == ch.Length - 1)
                            return false;
                    }
                }
                if (count > 1)
                    return false;
                return true;
            }                     
        }

你可能感兴趣的:(c#)