版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yzy85/article/details/82228653
C#后台使用正则表达式:
string pattern = @"^[0-9a-zA-Z_]{1,10}$";//字母数字下划线,1到10位
bool result = false;
if (!string.IsNullOrEmpty(this.txtNewPwd.Text.Trim()))
{
result = System.Text.RegularExpressions.Regex.IsMatch(this.txtNewPwd.Text, pattern);
if (!result)
{
throw new Exception("密码为字母数字下划线组合且最多10位");
}
}