I have a postcode array:
$firstPostcode = array(
'se1',
'ec2a',
'se16',
);
I need to validate users first 4 chars of a uk postcode against the above array.
Problem I have is I need to loop through one char at a time. Some input maybe 4 chars or 3 with a space.
I have tried preg match and in array but can’t solve it after hours of googling
Thanks for any advice.
The problem I am having is its matching the whole array not starting 4 chars
You should be able to match with a single regexp:
The creates a regexp like this:
This matches one of your prefixes at the start of the string (skipping any spaces first) and is case-insensitive.