【发布时间】:2011-10-19 21:54:52
【问题描述】:
我有这个当前代码,允许我从注册表中检查用户的名字,以确保它只包含字母、空格和破折号。但是如何启用检查多个字段(例如姓氏)。
/* Checks if the first name only includes letters, dashes or spaces */
if(preg_match("/^[a-zA-Z -]+$/", $_POST['firstname']) == 0)
$errors .="Your name must only include letters, dashes, or spaces.";
我已经尝试了以下方法,但它似乎只检查一个或另一个,而不是两个。
if(preg_match("/^[a-zA-Z -]+$/", $_POST['firstname'], $_POST['lastname']) == 0)
还有:
if(preg_match("/^[a-zA-Z -]+$/", $_POST['firstname'] and $_POST['lastname']) == 0)
提前感谢您的任何建议。
【问题讨论】:
标签: php validation preg-match