下面是我的正则表达式,只允许在名字和姓氏中使用单引号和连字符的字母和空格
$no_digit = array('firstname'=>$_POST['firstname'],'lastname'=>$_POST['lastname'],'city'=>$_POST['city']
,'country'=>$_POST['country'],'state'=>$_POST['state']);
foreach($no_digit as $index => $text){
echo '<br>regex = ' . preg_match("#[a-zA-Z - ']#",$text);
$error_flag = true;
$error[$index] = "Wrong Character Found";
}
我不知道它是不是在做我想要的,请有人告诉我应该怎么做,或者我错过了什么,或者做错了什么…
if(preg_match("~[^a-zA-Z'-']~",$text)){
$error_flag = true;
$error[$index] = "Wrong Character Found";
}