如何使用正则表达式在php名称字段中仅允许空格和alpha
大家好,下面是我的正则表达式,只允许字母表和空格在名字和姓氏中使用单引号和hypen如何使用正则表达式在php名称字段中仅允许空格和alpha,php,regex,Php,Regex,大家好,下面是我的正则表达式,只允许字母表和空格在名字和姓氏中使用单引号和hypen $no_digit = array('firstname'=>$_POST['firstname'],'lastname'=>$_POST['lastname'],'city'=>$_POST['city'] ,'country'=>$_POST['country'],'state'=>$_POST['state'])
$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";
}
$no\u digit=array('firstname'=>$\u POST['firstname'],'lastname'=>$\u POST['lastname'],'city'=>$\u POST['city']
,“国家”=>$邮政[“国家”],“州”=>$邮政[“州”];
foreach($index=>$text时无数字){
echo“
regex=”.preg_match(#[a-zA-Z-']#“,$text);
$error\u flag=true;
$error[$index]=“发现错误字符”;
}
我不知道它不是在做我想做的事,请有人告诉我应该怎么做,或者我错过了什么,或者做了完全错误的事…谢谢,它没有接受宣传和单曲,我把它改为[~[^a-zA-Z-\']]~],但勒克瑙不应该起作用。我们需要逃避,因为它不代表和谐
if(preg_match("~[^a-zA-Z\-']~",$text)){
$error_flag = true;
$error[$index] = "Wrong Character Found";
}