常用正则表达式 check

本文介绍了一系列常用的正则表达式验证方法,包括电话号码、数字、小数、带符号数字、电子邮件地址及中文字符的验证。通过具体示例展示了如何使用这些正则表达式进行数据验证。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

        private static Regex RegPhone = new Regex("^[0-9]+[-]?[0-9]+[-]?[0-9]{1}$");
		private static Regex RegNumber = new Regex("^[0-9]+{1}$");
		private static Regex RegNumberSign = new Regex("^[+-]?[0-9]+{1}$");
		private static Regex RegDecimal = new Regex("^[0-9]+[.]?[0-9]+{1}$");
		private static Regex RegDecimalSign = new Regex("^[+-]?[0-9]+[.]?[0-9]+{1}$"); //等价于^[+-]?\d+[.]?\d+$
		private static Regex RegEmail = new Regex("^[\\w-]+@[\\w-]+\\.(com|net|org|edu|mil|tv|biz|info){1}$");//w 英文字母或数字的字符串,和 [a-zA-Z0-9] 语法一样 
		private static Regex RegCHZN = new Regex("[\u4e00-\u9fa5]");//是否有中文


 一个例子:

 

		#region 中文检测

		/// <summary>
		/// 检测是否有中文字符
		/// </summary>
		/// <param name="inputData"></param>
		/// <returns></returns>
		public static bool IsHasCHZN(string inputData)
		{
			Match m = RegCHZN.Match(inputData);
			return m.Success;
		}	

		#endregion


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值