我正在开发一个网站,我在其中使用!preg_match("~/^[a-zA-Z ]*$/~",$name)
当用户在HTML FORM字段中写下他/她的NAME时,只有LETTERS允许写入如果编号写入消息出现“只允许字母”....但是它需要数字和字母。该怎么办???这是我的代码:
<?php
$nErr = $naErr = $cErr = "";
$id = $name = $color = "";
if (isset($_POST["submit"])) {
$id = $_POST["id"];
$name = $_POST["name"];
$color = $_POST["color"];
if (!preg_match("[0-9]",$id))
{
$nErr = "Only number allowed";
}
else if (!preg_match("~/^[a-zA-Z ]*$/~",$name))
{
$naErr = "Only letters allowed";
}
else if (!preg_match("~/^[a-zA-Z ]*$/~",$color))
{
$cErr = "Only letters allowed";
}
}
?>