I entered '2' as an example to show you what pops up. I am from the UK, by the way.
"Incorrectly formatted postal code" when entering "ZIP" for purchasing Microsoft 365
When entering my postcode it says incorrect format when trying to register my new bank card what can - Google Wallet Community
US Zip Code - Validate 2 formats - English - thirty bees forum
what is the correct postal code format for adding your micrsoft account ?
What is the standard postcode format?
What is the UK postcode format?
What is the German postcode format?
Videos
As stated. I already attempted with the "usual" formatting. Still, I get the error:
Could someone please help resolve this?
Thank you in advance.
Sincerely,
Victor
Hi Victor, Have I got the right country and zip code, that corresponds to yours: ZIP Code 11427 Map, Demographics, More for Jamaica, NY (unitedstateszipcodes.org)
Try Global Customer Service phone numbers - Microsoft Support
I am attempting to add a payment method, but I am unable to do so because of an incorrectly formatted postal code. Could you please provide the correct format for a postal code? In Nigeria, our postal code typically consists of a PMB followed by a number and location name, such as PMB 01, Garki.
Hello Ali,
Thank you for reaching out to this forum. I'm Ravi, just like you, a fellow Microsoft user and I'm here to help you with your question today.
I understand your concern as there are issues with updating the postal address on your Microsoft account.
Could you please let you know if you're updating the address based on "United States"? What is the region you have selected?
If you're updating a foriegn address, kindly make sure right region is selected.
Hope this information would be useful to you. Please feel free to get back if you need any additional info.
Thank you! Ravikumar Help the next person who has this issue by indicating if this reply solved your problem. Click Yes or No below.
Postcodes always end with digit-letter-letter. Simply look for a space at the 4th character before the end of the string and if it's not there, insert it.
The space is actually always at the same position for fully qualified UK Postcodes. It is just before the last 3 digit/letters
So first validate that it is a real UK postcode and it matches the format, then do this:
$postcode = 'E154EZ';
if( isValidPostcode($postcode) ){
$postcode = str_replace(' ','',$postcode);
$postcode = wordwrap($postcode, strlen($postcode)-3,' ', true);
}
PS. You can get the UK Postcode validation regexes + extra info from here
There are 6 possible formats for postcodes in the UK:
- A9 9AA
- A9A 9AA
- A99 9AA
- AA9 9AA
- AA9A 9AA
- AA99 9AA
I think there need to be two parts to your solution. The first is to validate the input; the second is to grab that first part.
Validation
This is really important, even though I realise you have said this is not what you are trying to do, but without it you are going to struggle to get the right prefix and possibly send your drivers to the wrong place!
There are a couple of ways you can do it, either use a 3rd party to help you capture a complete & correct address (many available including http://www.qas.co.uk/knowledge-centre/product-information/address-postcode-finder.htm (my company)), or at a minimum use some reg-ex / similar sanity testing to validate the postcodes - such as the links Dmitri gave you above.
If you look at the test cases you have listed - W1ABC and W10ABC are not valid postcodes - if we get that bit correct then the next bit becomes a lot easier.
Extract the Prefix
Assuming you now have a full, valid postcode getting just the first part (outcode) becomes a lot easier - with or without spaces. Because the second half (incode) has a standard format of 9AA, digit-alpha-alpha, I would do it by spotting and removing this, leaving you with just your outcode whether it be W1 From W1 0AA, or W10 from W10 0AA.
Alternatively, if you are using a 3rd party to capture the address - most of them will be able to return the incode and outcode separately for you.
In php I do
$first=trim(substr(trim($postcode),0,-3));
To get the first section of the postcode. I've been using it for years and just works. It doesn't matter whether the user includes the space (or 2 spaces) in middle, because the last section is always 3 characters. I work for a distribution company, and we get charged more for certain postcode areas. You will have a problem is somebody enters their postcode incorrectly, if they miss a character from the end.
If the above isn't good enough.
You can validate whether the postcode the user gave you is valid, then http://postcodes.io/ can help.
http://api.postcodes.io/postcodes/W11%202AQ will give you back some JSON with whether the postcode is valid.
{
"status": 200,
"result": {
"postcode": "W11 2AQ",
"quality": 1,
"eastings": 524990,
"northings": 181250,
"country": "England",
"nhs_ha": "London",
"longitude": -0.200056238526337,
"latitude": 51.5163540527233,
"parliamentary_constituency": "Kensington",
"european_electoral_region": "London",
"primary_care_trust": "Kensington and Chelsea",
"region": "London",
"lsoa": "Kensington and Chelsea 004A",
"msoa": "Kensington and Chelsea 004",
"nuts": "Colville",
"incode": "2AQ",
"outcode": "W11",
"admin_district": "Kensington and Chelsea",
"parish": "Kensington and Chelsea, unparished area",
"admin_county": null,
"admin_ward": "Colville",
"ccg": "NHS West London (Kensington and Chelsea, Queenís Park and Paddington)",
"codes": {
"admin_district": "E09000020",
"admin_county": "E99999999",
"admin_ward": "E05009392",
"parish": "E43000210",
"ccg": "E38000202"
}
}
}
Part of the JSON is an "outcode": "W11", which I think is exactly what you are looking for.
You could also use the "eastings":524990,"northings":181250, fields to calculate the straight line distance from the restaurant to the user. The units are metres. Use Pythagoras.