Then you have a problem. The big problem is that you use something as FK that is used elsewhere, otherwise it would have been rather simple to change in the database.
But I'm not wrong. You just need to find out if the user have placed a space or not, then make sure that there is one version with a space and one without. It have nothing to do with the database search in itself, it's done best in PHP.
One idea is to use [man]substr[/man] and [man]is_numeric[/man] to find the first number, then use [man]substr_replace[/man] to add or remove the space in the second alternative.
Edit: Another way to solve it is to create a new column in the database where you have all the codes in the same fashion. Then you can do search against that column instead.