I have a number of restaurants who all deliver to certain postcode areas in London, for example:
When someone searches for a restaurant that delivers to their home, they enter their full postcode.
Some people enter the postcode correctly with the space, some of them just enter all letters and numbers attached, without a space separator. To harmonize things, I remove any space in the postcode before attempting a match.
So far, I used to match the postcode to the prefixes by just checking if it starts with the prefix in question, but then I realized that this is not foolproof:
WC1E123
=> correct match for WC1
W1ABC
=> correct match for W1
W10ABC
=> incorrect match for W1
, should only match the W10
prefix
How can I know, given a full postcode with no space, if it matches a given prefix, while not failing the W1
/ W10
test above?
Is there any solution at all to the problem, that would not involve forcing the customer to enter the postcode with the space at the correct position?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…