xiao Posted December 17, 2007 Share Posted December 17, 2007 How would a regex for a 4 digit postal code like this look like? 2390 - First number is 1-9 - #2 and #3 are 0-9 - Last is always a 0 I tried preg_match('^[1-9]{1}[0-9]{2}0$', $postcode) And preg_match('^[1-9]{1}[0-9]{2}[0]{1}$', $postcode) But they always give a false. Quote Link to comment Share on other sites More sharing options...
effigy Posted December 17, 2007 Share Posted December 17, 2007 preg_match('^[1-9]{1}[0-9]{2}0$', $postcode) This is correct and can be reduced to ^[1-9][0-9]{2}0$. Quote Link to comment Share on other sites More sharing options...
xiao Posted December 17, 2007 Author Share Posted December 17, 2007 thank you, so my problem's somewhere else then... Quote Link to comment Share on other sites More sharing options...
effigy Posted December 18, 2007 Share Posted December 18, 2007 What's in $postcode? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.