/// <summary>
/// 判断string类型否为数字
/// </summary>
/// <param name="strNumber"></param>
/// <returns></returns>
public static bool IsNumber(string strNumber)
{
string strValidRealPattern = "^([-]|[.]|[-.]|[0-9])[0-9]*[.]*[0-9]+$";
string strValidIntegerPattern = "^([-]|[0-9])[0-9]*$";
return !Regex.IsMatch(strNumber, "[^0-9.-]") &&
!Regex.IsMatch(strNumber, "[0-9]*[.][0-9]*[.][0-9]*") &&
!Regex.IsMatch(strNumber, "[0-9]*[-][0-9]*[-][0-9]*") &&
Regex.IsMatch(strNumber, "(" + strValidRealPattern + ")|(" + strValidIntegerPattern + ")");
} /// <summary>
/// 判断string类型否为正整数+0
/// </summary>
/// <param name="strNumber"></param>
/// <returns></returns>
public static bool IsPositive(string strNumber) => Regex.IsMatch(strNumber, "^\\d+$"); /// <summary>
/// 判断string类型否为金额
/// </summary>
/// <param name="strNumber"></param>
/// <returns></returns>
public static bool IsAmount(string strNumber) => Regex.IsMatch(strNumber, "^[0-9]+(.[0-9]{2})?$"); /// <summary>
/// 判断string类型否为手机号
/// </summary>
/// <param name="strPhone"></param>
/// <returns></returns>
public static bool IsPhone(string strPhone) => Regex.IsMatch(strPhone, "^0?(13[0-9]|15[012356789]|18[012356789]|14[012356789]|17[012356789])[0-9]{8}$"); /// <summary>
/// 判断string类型否为固定电话号
/// </summary>
/// <param name="strTel"></param>
/// <returns></returns>
public static bool IsTel(string strTel) => Regex.IsMatch(strTel, "^(0[0-9]{2,3}-)?([2-9][0-9]{6,7})+(-[0-9]{1,4})?$"); /// <summary>
/// 判断string类型否为邮编
/// </summary>
/// <param name="strZipCode"></param>
/// <returns></returns>
public static bool IsZipCode(string strZipCode) => Regex.IsMatch(strZipCode, "[0-9]{6}"); /// <summary>
/// 判断string类型否为Email
/// </summary>
/// <param name="strEmail"></param>
/// <returns></returns>
public static bool IsEmail(string strEmail) => Regex.IsMatch(strEmail, "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*"); /// <summary>
/// 判断是否为日期
/// </summary>
/// <param name="dateStr"></param>
/// <returns></returns>
public static bool IsDateString(string dateStr) => DateTime.TryParse(dateStr, out var date);

.Net常用正则判断方法的更多相关文章

  1. String类的常用判断方法使用练习

    选取了一些常用的判断方法进行了使用练习,后续跟新其他方法 package StringDemo; // String类的判断方法解析 // 1:boolean equals(); // 判断字符串是否 ...

  2. js数据类型的判断方法

    判断js中的数据类型有一下几种方法:typeof.instanceof. constructor. prototype. $.type()/jquery.type(),接下来主要比较一下这几种方法的异 ...

  3. JS中的原始类型和判断方法

    ECMAScript 中定义了 7 种原始类型: Boolean String Number Null Undefined Symbol(新定义) BigInt(新定义) 注意: 原始类型不包含 Ob ...

  4. 【跟着子迟品 underscore】常用类型判断以及一些有用的工具方法

    Why underscore 最近开始看 underscore.js 源码,并将 underscore.js 源码解读 放在了我的 2016 计划中. 阅读一些著名框架类库的源码,就好像和一个个大师对 ...

  5. Underscore.js 常用类型判断以及一些有用的工具方法

    1. 常用类型判断以及一些有用的工具方法 underscore.js 中一些 JavaScript 常用类型检查方法,以及一些工具类的判断方法. 首先我们先来谈一谈数组类型的判断.先贴出我自己封装好的 ...

  6. 干货:结合Scikit-learn介绍几种常用的特征选择方法

    原文  http://dataunion.org/14072.html 主题 特征选择 scikit-learn 作者: Edwin Jarvis 特征选择(排序)对于数据科学家.机器学习从业者来说非 ...

  7. 结合Scikit-learn介绍几种常用的特征选择方法

    特征选择(排序)对于数据科学家.机器学习从业者来说非常重要.好的特征选择能够提升模型的性能,更能帮助我们理解数据的特点.底层结构,这对进一步改善模型.算法都有着重要作用. 特征选择主要有两个功能: 减 ...

  8. jquery常用的一些方法

    一.选择网页元素(标签选择器) $(document) //选择整个文档对象 $('#myId') //选择ID为myId的网页元素 $('div.myClass') // 选择class为myCla ...

  9. (转)Java中使用正则表达式的一个简单例子及常用正则分享

    转自:http://www.jb51.net/article/67724.htm 这篇文章主要介绍了Java中使用正则表达式的一个简单例子及常用正则分享,本文用一个验证Email的例子讲解JAVA中如 ...

随机推荐

  1. spring boot2.03 spring cloud Finchley.RELEASE遇到的问题

    1.spring cloud bus 本地不能更新 原因是@RefreshScope注解要加在需要更新的controller上 2.No instances found of configserver ...

  2. DB2与oracle类型对比

    本文摘自http://www.cnblogs.com/cy163/archive/2010/11/17/1880280.html 做过DB2数据库应用迁移的工程师,了解IBM MTK工具在迁移过程中所 ...

  3. linux下安装php php-fpm(转载)

    centos安装php php-fpm 1.下载php源码包http://www.php.net/downloads.php2 .安装phptar -xvf php-5.5.13.tar.bz2cd ...

  4. adb占用

    输入netstat -ano | findstr "5037" .然后会弹出提示告诉你哪些进程占用了该端口,记住非0地址的后面的数字 打开任务管理器,点击“进程“,“查看”-“选择 ...

  5. 安装指定版本的docker

    安装 Docker 从 2017 年 3 月开始 docker 在原来的基础上分为两个分支版本: Docker CE 和 Docker EE. Docker CE 即社区免费版,Docker EE 即 ...

  6. 2018.08.29 hdu3507 Print Article(斜率优化dp)

    传送门 这应该算是斜率优化的模板题了. 就是要求打印n个数,每个数有一个参数a[i],每打印一段连续的数[l,r]需要的花费是(a[[l]+...+a[r])2+m" role=" ...

  7. CentOS里vim基本操作

    1.关于退出 :wq!  ----强制保存退出 :wq  ---- 保存退出 :x   ----- 作用和:wq 一样 ZZ  ---- 作用和:wq一样,(注意Z是大写的,并且不是在命令模式) :q ...

  8. Mac pro 安装IntelliJ IDEA 2017版

    1.官网下载这个版本https://www.jetbrains.com 2.点击下载即可 3.下载好后放入本地 4.启动mac终端进行破解 输入命令:sudo vim /private/etc/hos ...

  9. SqlCommand和SqlDataAdapter的区别

    SqlDataAdapter对象 一.特点介绍1.表示用于填充 DataSet 和更新 SQL Server 数据库的一组数据命令和一个数据库连接.2.在SqlDataAdapter和DataSet之 ...

  10. PAT甲 1009. Product of Polynomials (25) 2016-09-09 23:02 96人阅读 评论(0) 收藏

    1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...