首页 > 解决方案 > 任何人都可以解决 C# regx 表达式

问题描述

  1. 至少一个小写字母,
  2. 至少有一个大写字母,
  3. 至少特殊字符,
  4. 至少一个数字
  5. 至少 8 个字符长度

问题在 regx 模式中的“/d”处显示错误

private void txtpassword_Leave(object sender, EventArgs e) {
    Regex pattern = new Regex("/^(?=.*[a-z])(?=.*[A-Z])(?=.*/d)(?=.*[#$@!%&*?])[A-Za-z/d#$@!%&*?]{10,12}$/");
    if (pattern.IsMatch(txtpassword.Text)) {
        MessageBox.Show("valid");
    } else {
        MessageBox.Show("Invalid");
        txtpassword.Focus();
    }
}

标签: c#

解决方案


试试这个:

^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%\^&\*])(?=.{8,})

测试


推荐阅读