cshtml中正则表达式使用后台代码

//定义变量
bool a = false;
//正则表达式
string b = @" ^ (13[0 - 9] | 14[5 | 7] | 15[0 | 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9] | 18[0 | 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9])\d{ 8}
$";
//检查字符串与正则表达式是否匹配,结果赋值
//Regex需要引用using System.Text.RegularExpressions
//name是要输入的内容
a = Regex.IsMatch(name, b);
//不匹配
if (a == false)
{
Response.Write("<script>alert('失败')</script>");
}
//匹配
else
{
Response.Write("<script>alert('成功')</script>");
}

posted @ 2019-02-22 10:52  Ancestors  阅读(577)  评论(0编辑  收藏  举报