I found this regex on the net, but I need to modify it so that it supports postcodes without spaces (i.e. IG57DH). At the moment it will only support postcodes with spaces (i.e. IG5 7DH).
My cursory glance tells me it it parses out the space and uppercases it, so to speed things at their end, strtoupper(), trim(), str_replace() the space, check result is between 5 and 9(?) chars long - then send to this service and the result can tell you if the Postcode exists.
Probably more useful if you are actually going to go on and make some decisions based upon locality.
Positive result retrieves: Pcode, lat, lng, East, North, shortened url, City or district, Ward.