对话框中需要输入字符串,数字。如何判断输入的数据是数字呢?

解决方案 »

  1.   

    Char.IsDigit();
    还可以用js或者正则表达式.
      

  2.   

    using System;public class IsDigitSample {
        public static void Main() {
            char ch = '8';        Console.WriteLine(Char.IsDigit(ch));                    // Output: "True"
            Console.WriteLine(Char.IsDigit("sample string", 7));    // Output: "False"
        }
    }
      

  3.   

    using System;public class IsNumberSample {
        public static void Main() {
            string str = "non-numeric";        Console.WriteLine(Char.IsNumber('8'));        // Output: "True"
            Console.WriteLine(Char.IsNumber(str, 3));    // Output: "False"
        }
    }
      

  4.   

    判断数字:
    string str; 
    ... 
    int i; 
    if(str != null && Regex.IsMatch(str,@"^\d+$")) 
     i = int.Parse(str);