asp.net中使用正则表达式

1.重写IsRegEx方法:

 private bool IsRegEx(string regEx, string value)
{
 try
 {
  Regex regex = new Regex(regEx);
  if (regex.IsMatch(value))
   return true;
  else return false;
 }
 catch (System.Exception)
 {
  return false;
 }
 finally
 {
 }
}

2.调用重写后的方法执行判断:

private bool isCorrectString(string value)
{
 return (IsRegEx("^[0-9]\\S*[a-zA-Z]\\S*",value));
}

原文地址:https://www.cnblogs.com/Believe/p/1667517.html