Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用正则表达式在php名称字段中仅允许空格和alpha_Php_Regex - Fatal编程技术网

如何使用正则表达式在php名称字段中仅允许空格和alpha

如何使用正则表达式在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'])

大家好,下面是我的正则表达式,只允许字母表和空格在名字和姓氏中使用单引号和hypen

 $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";
}