Home > How to ... ?, PHP, Quick Tips > Форматиране и проверка на UK Postcode

Форматиране и проверка на UK Postcode

 
	function UKPostcode($postcode) {
	        $postcode = strtoupper($postcode);
	        $postcode = preg_replace('/[^A-Z0-9]/', '', $postcode);
	        $postcode = preg_replace('/([A-Z0-9]{3})$/', ' \1', $postcode);
	        $postcode = trim($postcode);
 
	        if (preg_match('/^[a-z](\d[a-z\d]?|[a-z]\d[a-z\d]?) \d[a-z]{2}$/i', $postcode)) {
	            return $postcode;
	        } else {
	            return NULL;
	        }
	}
Categories: How to ... ?, PHP, Quick Tips Tags:
Вижте всички статии от
Technology lover
Този автор е написал 156 статии