So yesterday I asked a question to see if it were possible to remove invalid characters from a string and keeping only a few valid ones for a number formatter ( Removing (nearly) all non-numeric characters from a string)
The answer was excepted and it worked great. But I've been thinking about it and simply removing the invalid characters isn't the correct thing to do. I can't simply assume the rest of the characters that were input were indeed correct, It would be best practice to raise an error.
I'm wondering how I would go about raising an error if any of the characters not mentioned in my $sAllowedValues variable are input
All help appreciated!
The snippet of code validating what characters are allowed
$sAllowedValues = "/\+?[0-9 EeXxTt]*/";
preg_match_all($sAllowedValues, $sNumber, $sMatches);
var_dump($sMatches);