Hello,
I have a form and the user can add their phone number.
if they enter their phone number 1234567891 is there a way i can change it on my processing page to
123 456 7891
thank you
Add Spaces
Moderator: General Moderators
Re: Add Spaces
If they enter a 10 (strlen) digit (ctype_digit) number, grab (substr) the first three characters, the second three, and the last four, and output them with spaces in between.
You may want to do other things first like strip spaces and symbols.
Code: Select all
if (strlen($number) == 10 && ctype_digit($number)) {
$number = substr($number, 0, 3) . " " . substr($number, 3, 3) . " " . substr($number, 6);
}Re: Add Spaces
i am having trouble understanding this .. i have a 9 digit number that i need to put a space after every 3 characters 123456789 to 123 456 789
thank you
thank you
Re: Add Spaces
Use the above answer, but change the strlen comparison from 10 to 9.
Re: Add Spaces
perfect thank you both for your help