I have a form where one of the fields asks the user to enter a postcode.
Where i am handling the form i have a simple regex to try and stop invalid postcodes passing through, however when i am testing the program its not even allowing me to enter real postcodes.
What have i done wrong?
Below is my code…
// Check for a postcode:
if (preg_match (’/^[A-Z]{1,2}[0-9][0-9A-Z]?\s?[0-9][A-Z]{2}/g/’, $trimmed[‘postcode’])) {
$pcde = mysqli_real_escape_string ($dbc, $trimmed[‘postcode’]);
$pcde = StrToUpper($pcde);
} else {
echo ‘
Postcode - Pleae enter a valid postcode!
’;}
Thanks.