No matter if I input English or Chinese, why does it always prompt that it is illegal?
<code>$reg1='/\w{20,100}/'; $a=str_replace(" ","",$_POST['name']); if(preg_match($reg1, $a)){ echo "合法"; }else{ echo "不合法"; }</code>
No matter if I input English or Chinese, why does it always prompt that it is illegal?
<code>$reg1='/\w{20,100}/'; $a=str_replace(" ","",$_POST['name']); if(preg_match($reg1, $a)){ echo "合法"; }else{ echo "不合法"; }</code>
<code class="php">$reg1='/^.{20,100}$/u';</code>
w can only match letters+numbers+underscores
If there is no ^ $ restriction, it will always be true as long as there are more than 20 characters, such as 1000 a's.
u modifier makes the lower version of php Chinese-friendly. I tested php7, and it doesn’t matter whether you add u or not.
<code>$reg1='/([\x{4e00}-\x{9fa5}]|\w){20,100}$/u'; </code>
You try it, Chinese is also available