phone number

Links for php scripts

Moderators: egami, macek, gesf

Post Reply
icu90ucme
New php-forum User
New php-forum User
Posts: 23
Joined: Mon Jul 07, 2003 2:29 pm

Thu Aug 07, 2003 7:06 pm

using a form field a customer is going to enter his phone number in this format 1234567890.

can i have php "when the form field loses focus" to change this number into (123)456-7890

or do i have to use javascript i know it's possible in javascipt by using the onBlur=myphonescript command

User avatar
swirlee
Moderator
Moderator
Posts: 2257
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Thu Aug 07, 2003 7:11 pm

PHP is a server-side language, and cannot do anything on the client side after the page has loaded in the user's browser. In other words, use JavaScript. It's not terribly complicated. Though I'm not sure why you'd want to do it (why not just wait until the user submits the form and make the change internally?).
Image

sigix
php-forum Active User
php-forum Active User
Posts: 364
Joined: Mon Jul 14, 2003 9:39 pm
Location: /Earth/Xion

Thu Aug 07, 2003 11:16 pm

yep you can do in Javascript :idea:

icu90ucme
New php-forum User
New php-forum User
Posts: 23
Joined: Mon Jul 07, 2003 2:29 pm

Fri Aug 08, 2003 8:39 am

well im gonna have a lot of users inputting at the same time and i wanted to put the least amount of strain on my server and if i can do it client sider rather than server side it'll help a little

User avatar
swirlee
Moderator
Moderator
Posts: 2257
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Fri Aug 08, 2003 8:56 am

But if you're worried about having accurate data, you're going to have to validate the phone numbers again on the server side anyway, since anybody with JavaScript turned off could enter an arbitrarily-formatted value. Since you're probably doing form validation anyway (right?), doing this on the server side isn't going to make much of a difference.
Image

nathanwebb6
New php-forum User
New php-forum User
Posts: 27
Joined: Sat Jul 05, 2003 5:08 pm
Location: england uk
Contact:

Mon Sep 01, 2003 2:51 pm

on the process page after the form you could put this?

$p1 = substr($number, 1, 3);
$p2 = substr($number, 4, 6);
$p3 = substr($number, 7,10);

$finalnumber = "(" . $p1 . ")" . $p2 . "-" . $p3;
naya

nathanwebb6
New php-forum User
New php-forum User
Posts: 27
Joined: Sat Jul 05, 2003 5:08 pm
Location: england uk
Contact:

Mon Sep 01, 2003 2:52 pm

nathanwebb6 wrote:o wait, you wanted it when you lose focus. well u could still use that method if it will work for your needs
naya

Post Reply