Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 检查密码框文本是否包含字符和数字_C#_Wpf_Contains_Passwordbox - Fatal编程技术网

C# 检查密码框文本是否包含字符和数字

C# 检查密码框文本是否包含字符和数字,c#,wpf,contains,passwordbox,C#,Wpf,Contains,Passwordbox,我正在为插入用户创建一个WPF窗口,我正在使用PasswordBox为用户键入您的密码,但我不知道可以在passBox.password.Contains()中输入什么 我需要有关如何检查此密码框包含字符和数字的帮助?包含是错误的方法 在这里: Contains是错误的方法 在这里: 您可以使用正则表达式来检查它。它将是这样的: using System.Text.RegularExpressions; Regex regex = new Regex(@"^.*(?=.{4,10})(?=.*

我正在为插入用户创建一个WPF窗口,我正在使用
PasswordBox
为用户键入您的密码,但我不知道可以在
passBox.password.Contains()中输入什么


我需要有关如何检查此
密码框
包含字符和数字的帮助?

包含
是错误的方法

在这里:


Contains
是错误的方法

在这里:


您可以使用正则表达式来检查它。它将是这样的:

using System.Text.RegularExpressions;

Regex regex = new Regex(@"^.*(?=.{4,10})(?=.*\d)(?=.*[a-zA-Z]).*$");
if (regex.Match(passwordBox1.Password).Success)
{
  //the password match the rule
}
如果满足以下条件,则上述正则表达式匹配:

  • 在任何位置搜索至少一个数字
  • 在任何位置搜索至少一个大写或小写
  • 强制密码由4-10个字符组成

  • 您可以根据需要修改它

    您可以使用正则表达式检查它。它将是这样的:

    using System.Text.RegularExpressions;
    
    Regex regex = new Regex(@"^.*(?=.{4,10})(?=.*\d)(?=.*[a-zA-Z]).*$");
    if (regex.Match(passwordBox1.Password).Success)
    {
      //the password match the rule
    }
    
    如果满足以下条件,则上述正则表达式匹配:

  • 在任何位置搜索至少一个数字
  • 在任何位置搜索至少一个大写或小写
  • 强制密码由4-10个字符组成

  • 您可以修改它以满足您的需要

    我已经尝试过passBox.Password.Contains()但我不知道我需要在容器中放置什么我已经尝试过passBox.Password.Contains()但我不知道我需要在容器中放置什么非常感谢!我需要这个!非常感谢你!我需要这个!也非常感谢你!我也非常喜欢这个解决方案!我也喜欢这个解决方案