I need to validate submitted form data:
- To check whether fields are empty.
- Proceed to validate non-empty data.
x – allows only spaces, underscore, aplha numeric characters. y – checks whether it is an image or not.
I'm using below code, it does not work. It is not validating and printing error.
<?php
$validate = array(
'/^[a-z\d ]{4,20}$/i' => array('$x' => 'Please enter valid name.'),
'/^[a-z\d ]{4,20}$/i' => array('$y' => 'Please enter a real category.')
);
$error = '';
foreach ($validate as $key => $field)
{
if (preg_match($key,$field[0]))
{
$error.= $field[0];
}
}
if ($error)
{
echo $error;
exit;
}
$validatecome from? I guess it should be$regEx?it does not work. Does the validation pass when it should fail, does it fail when it should pass?