tags:

views:

37

answers:

1

I've been searching for a global postcode based regex but not found one. Anyone know of one that exists?

A: 

Not sure if this really makes sense to try to test for, I think it would be: 0-18 characters which can contain: 0-9 + the basic Latin alphabet + spaces, hyphens, parentheses and a Cyrillic letter.

And I'm not at all sure that even that would cover all possibilities.

ho1
Indian post codes are just six digits. `^\d{6}$`
Amarghosh
@Amarghosh: But I think I've seen that people sometimes put a space in the middle? And if that's correct, then even that simple regex becomes a bit more complex (though I'm not sure if spaces are required in any country so possibly you could just strip out all spaces before doing the match).
ho1
People put spaces while writing (for ease of reading I guess), but that's not the standard. But I agree that an all encompassing regex for any post code will be cumbersome.
Amarghosh
@ho1 Spaces are part of the format of UK postcodes. For example, "BS1 6XB". The space isn't generally considered as optional, so they're almost always written like that.
Matt Gibson