c#与正则表达式

    学习c#,进行格式验证时,自己花了很长时间学习了正则表达式,花了点时间,整理了一下,供大家参考一下,有什么错误,希望大神提出来.

  

using Sysyem.Text.RegularExpressions.  //必须引用的命名空间

案例一 :  验证电话号码

       Regex.Ismatch(str_telephone,@"6(\d{3,4}-)?\d{6,8}$");

 

案例二 :  验证输入密码条件

       Regex.Ismatch(str_password,@"[A-Za-z]+[0-9]");

 

 

案例三 :  验证邮政编码       

       Regex.Ismatch(str_postalcode,@"^\d{6}$");

 

 

案例四 :  验证手机号     

   Regex.Ismatch(str_handset,@"^[1][3-5]\d{9}$");

 

 

案例五 :  验证身份证号  

Regex.Ismatch(str_idcard,@"(^\d{18}$|^\d{15}$");

 

 

案例六 :  验证两位小数  

Regex.Ismatch(str_decimal,@"^[0-9]+\.[0-9]{2}$");

 

 

案例七 :  验证一年中的十二月份  

Regex.Ismatch(str_month,@"^(0?[[1-9]|1[0-2]]$");

 

 

案例八 :  验证一个月的三十一天

Regex.Ismatch(str_day,@"^((0?[[1-9]|((1|2)[0-9])|30|31)$");

 

 

案例九 :  验证数字输入

Regex.Ismatch(str_number,@"^[0-9]*$");

 

 

案例十 :  验证密码长度

Regex.Ismatch(str_Length,@"^\d{6-18}$");

 

 

案例十一 :  验证非零正整数

Regex.Ismatch(str_intNumber,@"^\+?[1-9][0-9]*$");

 

 

案例十二 :  验证非零负整数

Regex.Ismatch(str_intNumber,@"^\-?[1-9][0-9]*$");

 

 

案例十三 :  验证大写字母

Regex.Ismatch(str_UpChar,@"^\[A-Z]+$");

 

 

案例十四 :  验证小写字母

Regex.Ismatch(str_UpChar,@"^\[a-z]+$");

 

 

案例十五 :  检查重复出现的词

 

 

 

案例十六 :  替换字符

 

 

 

案例十七 : 拆分字符串

String[] _str=Regex.Split(txtSplit.Text,"[1-9]");

 

案例十八 : 验证输入字符

Regex.IsMatch(str_letter,@"^[A-Za-z]+$");

 

 

案例十九 : 验证中文汉字输入

Regex.IsMatch(str_chinese,@"^[\u4e00-\u9fa5]{1,}$");

 

 

案例二十 : 验证输入字符串

Regex.IsMatch(str_Length,@"^[.{8,}$");

 

 

 

案例二一 : 验证Email格式

       Regex.IsMatch(str_Email,

   @"^(([\w\.]+)@(([[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|((\w+\.?)+)@([a-zA-Z]{2,4}|[0-9]{1,3})(\.[a-zA-Z]{2,4}))$");

 

 

 

案例二二 : 验证Email格式

       Public bool IPCheck(string IP)

       {

       String num=@"(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)";

       return Regex.IsMatch(IP,("^"+num+"\\."+num+"\\."+num+"$"));

       }

 

 

案例二三 : 验证URL格式

 

Regex.IsMatch(str_url,@"http(s)?//([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?");

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值