更新时间:2022-02-13 16:42:18
你在表达式后面有 $
,在开头有 ^
,这意味着你正在接受正好一个字符.
You have the $
after your expression and the ^
in the beginning, which means you are accepting exactly one character.
编辑(基于评论):
您可以尝试查看您的输入字段是否仅具有有效字符,通过将其与此匹配(如果匹配,则表示没有无效字符):
You can try to see if your input fields only have valid characters, by matching it against this (if it matches, it means there are no invalid characters):
$rex = '/^[^<,"@$?=>|;#]+$/i'
你也可以反过来,即测试你的输入字段是否有任何无效字符,使用chaos提供的正则表达式:
You can also do the reverse, that is, test if your input fields have any invalid characters, using the regex provided by chaos:
$rex = '/[<,"@$?=>|;#]/';
这样,如果正则表达式匹配,则意味着您有无效字符.
This way, if the regex matches, then it means you have invalid characters.