且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

密码验证正则表达式

更新时间:2021-07-16 21:44:48

^(?=.*[^a-zA-Z])(?=.*[a-z])(?=.*[A-Z])\S{8,}$

应该可以.但是请注意,您只是在验证 ASCII 字母.Ä 不是满足您要求的字母吗?

should do. Be aware, though, that you're only validating ASCII letters. Is Ä not a letter for your requirements?

\S 表示除了空格之外的任何字符",因此通过使用它而不是点,并通过在字符串的开头和结尾锚定正则表达式,我们确保字符串不'不包含任何空格.

\S means "any character except whitespace", so by using this instead of the dot, and by anchoring the regex at the start and end of the string, we make sure that the string doesn't contain any whitespace.

我还删除了整个表达式周围不必要的括号.

I also removed the unnecessary parentheses around the entire expression.