为你的下一个项目创建 3 个密码正则表达式
正则表达式晦涩难懂,很难从头开始构建。
不过,不要被这些晦涩难懂的符号吓到,开发者社区可以提供帮助。
我在这里编写了三个密码正则表达式,供您在下一个 JavaScript 前端应用或 Node.js 后端应用中使用。
// PASSWORD REGEX FOR YOUR NEXT JAVASCRIPT APP
// regex for a basic password must be
// more than 8 chars
const PASSWORD_REGEX_1= /^[A-Za-z0-9]\w{8,}$/;
// more secure regex password must be
// more than 8 chars
// at least one number
const PASSWORD_REGEX_2 = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$/;
// more secure regex password must be :
// more than 8 chars
// at least one number
// at least one special character
const PASSWORD_REGEX_3= /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*]).{8,}$/;
您可以组合所有 3 个正则表达式来显示适当的警告消息。
检查正则表达式的优秀网站:
鏂囩珷鏉ユ簮锛�https://dev.to/petroskoulianos/3-password-regex-for-your-next-project-53fn