【发布时间】:2016-03-15 08:51:20
【问题描述】:
我想在 WPF 的密码框中测试我的输入密码,以便它唯一 aplhabets,数字和特殊字符..我做了以下代码bt循环直接进入Else Loop。我应该怎么做才能使其正常运行?
Regex regex = new Regex("^(?=.+[A-Za-z])(?=.+\\d)(?=.+[$@$!%*#?&])[A-Za-z\\d$@$!%*#?&]{8,}$");
if (regex.IsMatch(txtPassword.ToString()))
{
MessageBox.Show("Data Saved Correctly");
}
else
{
txtPassword.Clear();
MessageBox.Show("Password should contain atleast one alphabet,number & special character");
}
【问题讨论】:
-
显然你没有得到匹配 - 你的正则表达式没有按照你的想法做
-
txtPassword?的类型是什么 -
如果是
TextBox使用txtPassword.Text而不是'txtPassword.ToString()` -
txtPassword 是我在 WPF 中的密码框。显然你不能在密码框的情况下使用 txtpassword.Text。这就是我使用 .toString() 的原因
-
嘿@SeM txtPassword 是一个密码框而不是文本框。没有 .text 可用于此。另外我目前不知道为什么正则表达式无法应用于此
标签: c# asp.net regex wpf passwordbox