Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要将用户输入过滤为仅字母数字、逗号、句号和空格。我实际上在下面尝试了此代码,但其他不需要的字符正在通过。
if(!preg_match('/^[,. 0-9A-Za-z]/', $input) { echo "invalid"; }
我怎样才能使输入严格接受上述这些字符?
否定字符 ( ^) 需要进入字符类:
^
if(preg_match('/[^,\. 0-9A-Z]/i', $input)) { echo "invalid"; }