.NET正则表达式至6和20个字符之间验证密码与至少一个大写字母,一个小写字母和一个数字

.NET正则表达式至6和20个字符之间验证密码与至少一个大写字母,一个小写字母和一个数字

问题描述:

我需要一个正则表达式来验证密码具有以下规格:

I need a regex to validate passwords with the following specs:

它必须是字符,其中至少一个大写字母6和20之间,一个小写字母和一个数字

It must be between 6 and 20 characters with at least one upper case letter, one lower case letter and one digit

我觉得这个作品:

^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).{6,20}$

这是的测试用例的Regex英雄

的想法是使用正向前看符号,以保证至少一个小写字母,一个上字母和一个数字包含在密码中。然后作为最后一步,我只需指定一个点,允许在6-20个字符范围内的任何字符。

The idea is to use positive lookaheads to ensure that at least one lower case letter, one upper case letter, and one digit are contained within the password. And then as a last step I simply specify a dot to allow any characters in the 6-20 character range.