<?php
$userInput = 'YO264UU';
// remove all spaces and upper case
$userInput = strtoupper(preg_replace('/\s+/', '', $userInput));
if (isValidPostcode($userInput)) {
// Basic postcode formatting - add a space before the last 3 characters
$formatted = substr($userInput, 0, -3) . ' ' . substr($userInput, -3);
// now look up in db using $formatted
} else {
// invalid postcode!
}
var_dump($formatted);
Fatal error: Uncaught Error: Call to undefined function isValidPostcode() in /in/LOWQJ:7
Stack trace:
#0 {main}
thrown in /in/LOWQJ on line 7
Process exited with code 255.