zoukankan      html  css  js  c++  java
  • 判断是否是数字

     1 /// <summary>
     2 /// 是否是Decimal,空返回false
     3 /// </summary>
     4 /// <param name="str"></param>
     5 /// <returns></returns>
     6 private bool IsDecimal(string s)
     7 {
     8     bool isDec = true;
     9     try
    10     {
    11         Convert.ToDecimal(s);
    12     }
    13     catch
    14     {
    15         isDec = false;
    16     }
    17 
    18     return isDec;
    19 
    20 }
    21 
    22 /// <summary>
    23 /// 是否是整数,空返回false
    24 /// </summary>
    25 /// <param name="str"></param>
    26 /// <returns></returns>
    27 public static bool IsInt(string str)
    28 {
    29     if (str == string.Empty)
    30         return false;
    31     try
    32     {
    33         Convert.ToInt32(str);
    34         return true;
    35     }
    36     catch
    37     {
    38         return false;
    39     }
    40 }
    41 
    42 //判读是否是日期
    43 public bool IsDate(string strDate)
    44 {
    45     try
    46     {
    47         DateTime.Parse(strDate);
    48         return true;
    49     }
    50     catch
    51     {
    52         return false;
    53     }
    54 }
    55 
    56 
    57 
    58 //用正则表达式判断
    59 //是否是数字
    60 public static bool IsNumeric(string value)
    61 {
    62     return Regex.IsMatch(value, @"^[+-]?d*[.]?d*$");
    63 }
    64 //是否是整数
    65 public static bool IsInt(string value)
    66 {
    67     return Regex.IsMatch(value, @"^[+-]?d*$");
    68 }
  • 相关阅读:
    Python类知识点
    安装psycopg2时出错:Error: pg_config executable not found.
    top命令
    Ubuntu18.10创建软件图标
    初始化Redis密码
    Ubuntu修改root密码,ssh 允许root用户登录
    Flask_Migrate数据库迁移
    Ubuntu18.04 systemd开机自启
    dnspython
    记一次Celery的仇
  • 原文地址:https://www.cnblogs.com/haibing0107/p/5977444.html
Copyright © 2011-2022 走看看