分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

.Net常用正则判断方法

发布时间:2023-09-06 02:34责任编辑:彭小芳关键词:正则
原文:.Net常用正则判断方法

 ???????/// <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);
View Code

.Net常用正则判断方法

原文地址:https://www.cnblogs.com/lonelyxmas/p/10474506.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved