Take the entrance and cross out everything that is not a number.
// rm all but Numbers $input = '0123 abc #'; $output = preg_replace('#[^0-9]#', '', $input); echo($output);
Count the remaining numbers.
If it's 9 digits, add "+27"
If it's 11 digits, add "+"
If it is 10 digits longer or less than 9, then presumably this is not a valid phone number format?
Cups
source share