in reply to UK postcode regex
The (\d|o) has the letter o to cater for an incorrect o instead of a zero. To actually change it to a zero would require a second line (using the substitution operator). I don't know of any way to make that change in the regex line while it is being parsed... UPDATE: Looks like there are a couple of ways to do it in one line, including changing an incorrect letter o to a zero. I stand corrected :)# Check UK postcode format # Format is LD DLL, LLD DLL, LDD DLL, or LLDD DLL where L = letter, D += digit $postcode = uc($postcode); # Could be removed if you use the /i regex +switch if ($postcode !~ /^(([A-Z]\d|[A-Z][A-Z]\d|[A-Z]\d\d|[A-Z][A-Z]\d\d)\s( +\d|o)[A-Z][A-Z])$/i) { $error_msg .= "Invalid postcode for UK.<br /><br />\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: UK postcode regex
by tweetiepooh (Hermit) on Jan 20, 2006 at 14:48 UTC |