检查密码的高位,低位和符号 [英] checking a password for upper lower numbers and symbols
本文介绍了检查密码的高位,低位和符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下脚本检查密码的长度,大写,小写和数字.
I am using the below script to check my passwords for length, uppercase, lowercase and numbers.
如何更改它以使其检查FOR符号而不是对照符号?
How could I change it to make it check FOR symbols instead of against symbols?
<?php
$password = 'afsd323A';
if(
//I want to change this first line so that I am also checking for at least 1 symbol.
ctype_alnum($password) // numbers & digits only
&& strlen($password)>6 // at least 7 chars
&& strlen($password)<21 // at most 20 chars
&& preg_match('`[A-Z]`',$password) // at least one upper case
&& preg_match('`[a-z]`',$password) // at least one lower case
&& preg_match('`[0-9]`',$password) // at least one digit
)
{
echo 'valid';
}
else
{
echo 'not valid';// not valid
}
?>
推荐答案
您所需的正则表达式在下面
your desired regex is below
$pattern = ' ^.*(?=.{7,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$ ';
preg_match($pattern,$password);
这篇关于检查密码的高位,低位和符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文