Our website is made possible by displaying online advertisements to our visitors.
Please consider supporting us by disabling your ad blocker.
-
-
Dinosaur
-
Web Guru
Originally Posted by
Excalibur
Originally Posted by
Marc J
For perfectly valid reasons, I was trying to generate random, valid UK postcodes
And to a Man, Woman and Child, the entire MDD are wondering-
For heavens sake why?
Short answer: MYOB
Long answer: I'm writing something that needs to test for valid UK postcodes, and I needed some to test it with!
-
Originally Posted by
Marc J
So, I hit the button, and got one that differs from my own postcode by only the last two letters, and is only 5 doors away from me. Thankfully the matching phone number was nothing like mine!
I have everything privacy-wise locked up on my browser so there's no way it could have known where I am, and it's given me plenty further afield since, but the first one was almost spot on! What are the chances????
Yet many of us spend £2 every week actively trying to get 6 numbers we've picked to match 6 randomly picked numbers!
-
Web Guru
Originally Posted by
rth_discos
Yet many of us spend £2 every week actively trying to get 6 numbers we've picked to match 6 randomly picked numbers!
Well, the chances of winning the lottery (jackpot) is something like 1 in 14 million.
There are apparently 1.8 million UK postcodes, so the chances of the above random postcode generator getting yours exactly is nearly 8 times more likely than winning the lottery. So getting mine to all but the last 2 letters suddenly doesn't seem so spectacular....still freaked me out, though!
-
Nope loads of random postcodes for me.
-
Originally Posted by
Excalibur
And to a Man, Woman and Child, the entire MDD are wondering-
For heavens sake why?
Not if you're a software developer for a living.....makes perfect sense to me (been there, seen it, done it....enjoy the London postcodes and the variations in lengths)
-
Dinosaur
-
-
Web Guru
Originally Posted by
Imagine
Not if you're a software developer for a living.....makes perfect sense to me
(been there, seen it, done it....enjoy the London postcodes and the variations in lengths)
Not to mention postcodes being added all the time! It would be a lot simpler if I only needed to check for the correct format, something like: -
Originally Posted by
Regex
^(([gG][iI][rR] {0,}0[aA]{2})|((([a-pr-uwyzA-PR-UWYZ][a-hk-yA-HK-Y]?[0-9][0-9]?)|(([a-pr-uwyzA-PR-UWYZ][0-9][a-hjkstuwA-HJKSTUW])|([a-pr-uwyzA-PR-UWYZ][a-hk-yA-HK-Y][0-9][abehmnprv-yABEHMNPRV-Y]))) {0,}[0-9][abd-hjlnp-uw-zABD-HJLNP-UW-Z]{2}))$
But that would still allow invalid postcodes. Looks like the only solution is a database of valid codes to check against. Or http://postcodes.io/ looks interesting if relying on a 3rd party is OK. If anyone's interested, lots of good postcode related code tips here: https://stackoverflow.com/questions/...-comprehensive
Originally Posted by
Imagine
As Marc says in his signature at the moment.....In order to understand recursion you must first understand recursion (now THAT's one to get your head around).
You've noticed my ever-changing signature, then?
Last edited by Marc J; 08-09-2017 at 08:17 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules