When a user submit forms,i'm checking empty validation and data validation.
For ex:In data ,first field is name,i'll check whether user has entered any other characters else than alpha character's.if he has entered then will show him an error message.Name should contain minimum of 4 characters and max of 20 characters
I'm using this code but it is not working correctly.How to check the regex.
$validate = array("Category"=>"$productCategory", "Name" => "$productName");
$error = '';
foreach ($validate as $key => $field) {
if (preg_match('/^[a-z\d ]{4,20}$/i', $$field)) {
echo $error .= $field;
}
}
Thanks in advance!
$$fieldinstead of$fieldecho $error .= $field;pretty strange. Can anyone explain it's logic?