概率密码的正则表达式 [英] regular expression for password in probabilities
问题描述
hi
我要求密码采用四个像这样的三个选项中的任何一个....
密码必须使用以下四种字符类型中的至少三种的组合:
I.Atleast 1个大写字母(A – Z)
II.小写字母(a – z)
III.Atleast 1号(0 – 9)
IV.至少1个非字母数字符号(例如@"$%£!")
因此,有人可以在asp.net中以正则表达式验证器提供的正则表达式帮助我,还是可以通过其他任何方式对其进行验证?
hi
I have a requirement for the password to take any of the three options from four like.......
password must use a combination of at least three of the following four character types:
I.Atleast 1 upper case letters (A – Z)
II.Lower case letters (a – z)
III.Atleast 1 number (0 – 9)
IV.Atleast 1 non-alphanumeric symbol (e.g. @ ‘$%£!’)
So can anyone help me with the regular expression to be given in regular expression validator in asp.net or any other way where i can validate it?
推荐答案
%£! ')
因此,有人可以在asp.net中以正则表达式验证器提供的正则表达式来帮助我,还是可以通过其他任何方式对其进行验证?
%£!’)
So can anyone help me with the regular expression to be given in regular expression validator in asp.net or any other way where i can validate it?
使用正则表达式是一种不好的方法-这不是一个字符串匹配操作,它是一个字符计数操作,而正则表达式根本不擅长此操作.
用代码执行:遍历每个字符并计算其组.您可以在服务器端作为回发测试的一部分,也可以在客户端作为验证程序的一部分-完全由您决定.
A regex is a bad way to do this - this isn''t a string matching operation, it''s a character counting operation, and regexes are not good at that at all.
Do it in code: loop through each character and count it''s groups. You can do this either server side as part of the postback testing or client side as part of the validator - it''s up to you.
似乎它应该在服务器端实现,因此请在您的Button单击上调用此方法:
Hi,
it seems that it should implement on server side so call this method on your Button click:
bool ValidatePassword()
{
string pass = txtpass.Text;
bool result = false;
bool isDigit = false;
bool isLetter=false;
bool isLowerChar = false;
bool isUpperChar = false;
bool isNonAlpha = false;
foreach (char c in pass)
{
if (char.IsDigit(c))
isDigit = true;
if (char.IsLetter(c))
{
isLetter=true;
if (char.IsLower(c))
isLowerChar = true;
if (char.IsUpper(c))
isUpperChar = true;
}
Match m = Regex.Match(c.ToString(), @"\W|_");
if (m.Success)
isNonAlpha = true;
}
if (isDigit && isLetter && isLowerChar && isUpperChar && isNonAlpha)
result = true;
return result;
}
希望对您有帮助.
hope this will help you.
这篇关于概率密码的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!