密码验证的正则表达式 [英] Regular expressions for password validation
本文介绍了密码验证的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要验证符合以下条件的密码:
I need to validate a password that matches the following criteria:
- 最少 8 个字符
- 包含数字和字母的组合
- 不得强制使用特殊字符
下面的正则表达式是我想出来的:
The follow regular expression is what I came up with:
^{8,}.(?=*\d)(?=.*[a-zA-Z])&
但这失败了:
- !password1
- 密码1
- 密码1
据我所知,尝试调查 RegEx,{8,}
表示最小值为 8,不关心最大值,\d
指定数字,空格和特殊字符.a-z 是有道理的.
From what I can gather, trying to investigate RegEx, {8,}
means minimum of 8 and don't care about the maximum, \d
specifies digits, whitespaces and special characters. The a-z makes sense.
推荐答案
尝试:
^(?=.*\d)(?=.*[a-zA-Z]).{8,}$
这篇关于密码验证的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文