1
我正在根据表单值创建一个正则表达式数组,并使用错误的用户输入失败的函数。我每次运行的网站,我收到以下错误:使用正则表达式数组进行PHP验证
警告: eregi()[function.eregi]:REG_EMPTY
我不知道什么是错。请看看我的代码和帮助。谢谢!
$error_log = array();
// Checks if user inputed data matches the default values
$arr = array(
'name' => 'First Name Last Name',
'month' => 'MM',
'day' => 'DD',
'year' => 'YYYY',
'address1' =>'Address Line 1',
'address2' => 'Address Line 2',
'email' => '[email protected]'
);
$regex = array(
'name' => "^[a-z .'-]+$",
'month' => "^((0[1-9])|(1[0-2]))$ ",
'day' => "0?[1-9]|[1-2][0-9]|3[0-1]",
'year' => "^(19|20)\d{2}$",
'address1' => "/^[a-zA-Z0-9 ]*$/",
'address2' => "/^[a-zA-Z0-9 ]*$/",
'email' => "^[A-Z0-9._%-][email protected][A-Z0-9.-]+\.[A-Z]{2,4}$"
);
/*
Runs validation on the form values and stops procesing if the form does not have the correct values
*/
function regexValidate($form_value, $regex, $key){
if(!eregi($regex[$key],$form_value)){
return true;
}
return false;
}
*(阿里纳斯)就可以扩大*由于PHP的5.3.0,`eregi`不赞成使用[PCRE扩展](http://de2.php.net/manual/en/book.pcre.php)。调用这个函数将发出一个`E_DEPRECATED`通知。查看[差异列表](http://de2.php.net/manual/en/reference.pcre.pattern.posix.php)以获得转换为PCRE的帮助。 – Gordon 2011-02-14 16:40:04
我建议你尝试输出`$ key`和`$ regex [$ key]`来查看你正在尝试使用哪个正则表达式。如果在那里有问题(比如说,一个意外的键值),你将得到一个null regex馈给eregi(),导致你的错误。正如戈登指出的那样,eregi()已被弃用。我认为preg_match()将是一个更好的选择。 – 2011-02-14 16:40:12