Ideally you need a postcode database, but depending on your country, you usually have to pay a fee for that data (the UK does).
Another approach is to query Google Maps API and get the long/lat from there, and then it’s some math to compare against a given long/lat to find out the distance. It’s been a while since i’ve done that math, so you would have to google to find out.