I am working on creating an array of regular expressions based on form values and using a function that fails on the wrong user input. Every time I run the website I receive the following error:
Warning: eregi() [function.eregi]: REG_EMPTY
I do not know what is wrong. Please take a look at my code and help. Thank you!
$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._%-]+@[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;
}
eregi
is deprecated in favor of the PCRE extension. Calling this function will issue anE_DEPRECATED
notice. See the list of differences for help on converting to PCRE.$key
and$regex[$key]
to see what regex you're attempting to use. If there's a problem there (say, an unexpected key value) you're going to have a null regex fed to eregi(), causing your error. As Gordon points out, eregi() is deprecated. I think preg_match() will be a better choice.regexValidate
.