02-19-2008, 04:53 PM
|
#33 (permalink)
|
|
The Wanderer
Join Date: Feb 2008
Location: Blackpool, England
Posts: 16
Thanks: 2
|
If your based in the UK and stuck for Postcode and Telephone formatting ideas.
Try these
php Code:
// POSTCODES - will work for every UK postcode including the very strange GIRO Bank one.$pattern = '/(^gir\s0aa$)|(^[a-pr-uwyz]((\d{1,2})|([a-hk-y]\d{1,2})|(\d[a-hjks-uw])|([a-hk-y]\d[abehmnprv-y]))\s\d[abd-hjlnp-uw-z]{2}$)/i'; if (! preg_match($pattern, $postcode)) { // Display Error}// Valids all uk numbers including +44's or anything like that$telephone = str_replace(" ", "", $telephone); $telephone = str_replace("+", "", $telephone); $pattern = '/^01[1-9]{1}|02[03489]{1}|05[0-9]|07[056789]{1}|08[047]{1}|441[1-9]{1}|442[03489]{1}|445[0-9]|447[056789]{1}|448[047]{1}$/Ui'; if (! preg_match($pattern, $telephone)) { // Display Error} else { if(substr($telephone, 0, 2) == "44") { $telephone = "0" . substr($telephone, 3, strlen($telephone)); } if(strlen($telephone < 10)) { // Display Error } }
Last edited by Andrial12 : 02-19-2008 at 09:00 PM.
Reason: Removed some code relating to a website I produced that isn't important to the workings of the code
|
|
|
|