I am trying to make a regular expression to match this mailing address:
4F 50 Adele Street 01234 London
Here is my code:
if( !(preg_match('/[1-9]{5}[A-Za-z] [1-9] [A-Za-z\.]+ [A-Za-z\.]+ [0-9]{5} [A-Za-z\.]+/', $address))){
return true;
}
}
Try this RE:
/[1-9][a-z] [1-9][0-9] [a-z.]+ [a-z.]+ [0-9]{5} [a-z.]+/i
Changes:
{5}
[1-9]
to [1-9][0-9]
.
inside bracketsA-Za-z
, I just write a-z
and use the i
modifier to make it case insensitive