gpt4 book ai didi

php - 密码验证php正则表达式

转载 作者:可可西里 更新时间:2023-10-31 22:12:18 25 4
gpt4 key购买 nike

我是正则表达式的新手。
我需要使用 php 验证密码,并使用正则表达式执行以下密码策略:

密码:

  1. 必须至少有 8 个字符
  2. 必须有 2 个数字
  3. 允许的符号是:! @# $ % *

我尝试了以下方法:/^(?=.*\d)(?=.*[A-Za-z])[0-9A-Za-z!@#$%]$/

最佳答案

以下内容完全符合您的要求:^(?=.*\d.*\d)[0-9A-Za-z!@#$%*]{8,}$

Online demo <子> <<< You don't need the modifiers, they are just there for testing purposes.

解释

  • ^ : 匹配字符串的开头
  • (?=.*\d.*\d) : 正向前瞻,检查是否有2位数字
  • [0-9A-Za-z!@#$%*]{8,} : 匹配数字、字母和 !@#$%* 8次或更多次
  • $ : 匹配字符串结尾

关于php - 密码验证php正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18175644/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com