代码
 String Str = "1234567891012356565656565";

            Regex regex 
= new Regex(@"\d{6}");

            
//将匹配成功因为只要是6个数字的都匹配
            foreach (Match match in regex.Matches(Str))
            {
                Response.Write(match 
+ "<br/>");
            }

            
//匹配起始和末尾必须为6个数字
            regex = new Regex(@"^\d{6}$");

            
foreach (Match match in regex.Matches(Str))
            {
                Response.Write(match 
+ "<br/>");
            }

            String str1 
= "123456";
            
//其实和末尾为6个数字所以匹配成功.
            if (regex.IsMatch(str1))
            {
                Response.Write(
"Success!");
            }
            
else
            {
                Response.Write(
"Fail!");
            }

 正则表达式起始符和结束符的作用和验证手机号码等

 

验证手机号码

正则表达式起始符和结束符的作用和验证手机号码等

正则表达式起始符和结束符的作用和验证手机号码等

 

代码
 string str = "15012345678";

            
if (Regex.IsMatch(str,@"^0?1(3\d|5[03689])\d{8}$"))
            {
                Response.Write(
"Success!");
            }
            
else
            {
                Response.Write(
"Fail!");
            }

 

 正则表达式起始符和结束符的作用和验证手机号码等

 

代码
 //匹配月份加时间
            String str = "11月00:00";

            
if (Regex.IsMatch(str, @"^([1][0-2]|0?\d)月[0-2][0-3]:[0-5][0-9]$"))
            {
                Response.Write(
"Success!");
            }
            
else
            {
                Response.Write(
"Fail!");
            }

            
//IP地址字符串
            str = "192.168.1.1";

            
if (Regex.IsMatch(str, @"^((2[0-5][0-5]|1\d\d|\d\d|\d)\.){3}(2[0-5][0-5]|1\d\d|\d\d|\d)$"))
            {
                Response.Write(
"Success!");
            }
            
else
            {
                Response.Write(
"Fail!");
            }

 

 

 

相关文章:

  • 2021-12-23
  • 2021-12-23
  • 2021-12-23
  • 2021-12-20
  • 2021-11-21
  • 2021-12-23
  • 2021-12-31
猜你喜欢
  • 2021-11-30
  • 2021-05-14
  • 2022-12-23
  • 2021-11-29
  • 2021-12-18
  • 2022-01-02
相关资源
相似解决方案