4 ms·
How about chars in zip codes (afaik GB has chars in zip codes)? Input validation is usually a UX fail because there will be for sure one thing you miss (tradit
by mweibel 13y ago
How about chars in zip codes (afaik GB has chars in zip codes)?
Input validation is usually a UX fail because there will be for sure one thing you miss (traditional example: email address validation). Zip codes I'd rather don't check at all or check against a list of valid zip codes if really necessary.
- henrik_w 13y agoAs do Canadian ZIP-codes.
- jasonlotito 13y agoWell, that's the thing, Canada doesn't have ZIP codes. ZIP codes are purely an American system. Canada has postal codes, and you can easily verify the format of them, as well as the location of Canadian postal codes. So if you know the person is in Canada, you simply check against a different set of rules.
- rmc 13y ago(afaik GB has chars in zip codes) Yes the UK has letters in postcodes.
- jwdunne 13y agoAnd the regex to validate this is a monster, even noting that this still allows bad input: (GIR 0AA)|((([A-Z-[QVX]][0-9][0-9]?)|(([A-Z-[QVX]][A-Z-[IJZ]][0-9][0-9]?)|(([A-Z-[QVX]][0-9][A-HJKSTUW])|([A-Z-[QVX]][A-Z-[IJZ]][0-9][ABEHMNPRVWXY])))) [0-9][A-Z-[CIKMOV]]{2}) http://stackoverflow.com/questions/164979/uk-postcode-regex-comprehensive http://stackoverflow.com/questions/164979/uk-postcode-regex-...
- rmc 13y agoThe UK Government (after OSM took off) started to open source and release more data. You can download[1] the database of most of the UK postcodes[2] and their latitude & longitude. So if you want to really verify a GB postcode, you can just check it against the list [1] It's called 'Code Point Open' and you can 'order' it (for free) here http://www.ordnancesurvey.co.uk/business-and-government/products/opendata-products.html http://www.ordnancesurvey.co.uk/business-and-government/prod... [2] It's most of UK. It doesn't include Northern Ireland
- logn 13y ago> Input validation is usually a UX fail I agree in general. I think it was just a contrived example though in interest of discussing security/validation. Their example was in context of US users (and US zip-codes don't deviate from the pattern, but yes you could go one step further and reference the zip-code against the state and address using an API). Also, specifically on regex, I'd imagine \d is being used in places where validation against unicode would be buggy (whether in form validation or elsewhere). I think Java and JavaScript default to ASCII only though.
- jasonlotito 13y agoZIP codes are an American thing. ZIP codes are a specific system of postal codes. If you are talking about ZIP codes, it's American. If you are validating an American address, you'd want to validate using something that validates a ZIP code. If you get a Canadian address, you'd want to validate against that (which also happens to make it simple to validate against the province as well). And yes, if you shouldn't using the term ZIP codes and postal codes interchangeably and treating them the same way in your code.
- mweibel 13y agoInteresting. I'm swiss and usually our postal codes are translated to zip code. Would postal code be the generic translation then?