正则表达式来验证密码 [英] regular expression to validate the password

查看:148
本文介绍了正则表达式来验证密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,



正在使用asp.net c#project



任何人都可以提供帮助我编写一个正则表达式来验证在ASP.NET中的文本字段中输入的密码



密码的规则是:



1)密码中必须有大写字母。

2)密码中必须包含小写字母。

3)密码中必须有数字。

4)密码必须至少8个字符
5)密码不能包含非法字符,例如=,<,>,;,:,'

,或逗号(等号,大符号,小于符号,分号,冒号,

单引号,双引号,逗号)。



请帮帮我,



感谢@dvance。

Dear Friends,

am working on asp.net c# project

Can any one help me to write a regular expression to validate the password
entered on the text field in ASP.NET.
The rules for the password are:

1) There must be Upper case letters in the password.
2) There must be lower case letters in the password.
3)There must be numbers in the password.
4) Password must be minimum 8 characters
5) Password cannot contain illegal characters, such as =, <, >, ;, :, '
, " or comma (equal sign, greater sign, less than sign, semicolon, colon,
single quote, double quotes, comma).

Please help me,

Thanks in @dvance.

推荐答案

这是使用正则表达式非常不方便的典型示例之一,因为您必须预见所有可能的排列,这几乎是不可能的:字符的顺序不受约束,最大长度不受限制。



解决方案比这简单得多:扫描所有循环中的字符和cl将它们全部分为4个(未使用#4,检查最开始的长度)类别。您只需要记住发生的次数。然后,对于每个类别,在多重性上应用您的标准:在#1,#2和#3中,必须大于零,在#5中,应该为零。对于#5,而不是如,列出所有并将其写入一个字符串,以计算在该字符串中找不到字符。



这些方法将帮助您:

http://msdn.microsoft.com/en- us / library / dy85x1sa.aspx [ ^ ](对于规则#5,选中不包含),

http://msdn.microsoft.com/en-us/library/system.char.aspx [ ^ ]:

http://msdn.microsoft.com/en-us/library/d1x97616.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/yk2b3t2y.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/9s91f3by.aspx [ ^ ]。



-SA
This is one of the typical examples where using Regex would be extremely inconvenient, because you would have to foresee all possible permutation, which is nearly impossible: the order of characters is not constrained and maximum length is not limited.

The solution is much simpler than that: scan all characters in the loop and classify them all into 4 (#4 is not used, check up the length in the very beginning) categories you described. You would need to remember only the number of occurences. Then, for each category, apply your criteria on multiplicity: in #1, #2 and #3, must be greater then zero, in #5, should be zero. For #5, instead of "such as", list all and write it in one string, to calculate that a character is not found in that string.

These methods will help you:
http://msdn.microsoft.com/en-us/library/dy85x1sa.aspx[^] (for rule #5, check "not contains"),
http://msdn.microsoft.com/en-us/library/system.char.aspx[^]:
http://msdn.microsoft.com/en-us/library/d1x97616.aspx[^],
http://msdn.microsoft.com/en-us/library/yk2b3t2y.aspx[^],
http://msdn.microsoft.com/en-us/library/9s91f3by.aspx[^].

—SA


访问这里....





http://www.mkyong.com/regular-expressions/how-to-validate-password- with-regular-expression / [ ^ ]
visit here....


http://www.mkyong.com/regular-expressions/how-to-validate-password-with-regular-expression/[^]


您好,我在同一主题的CP上有一篇文章。请看一下:强密码验证 [ ^ ]
Hi, I have a post on CP on the same topic. Please have a look at this: Strong Password Validation[^]


这篇关于正则表达式来验证密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆