Log in

View Full Version : My Sign Up Form Help



impload
11-04-2009, 01:12 PM
Hi I have a sign up form and it is linked to various php scripts that send api calls.

The api we use marks this as correct:
Phone number: 8676544544

But this just brings an error:
Phone number: 545-645-4242
Phone number: (545) 445-2454
even if there are spaces in between.

Because of the dashes in between the numbers. How can I have the php script remove the dashes(-) in the phone number or even the spaces if there are any inputed? :cool:

newbtophp
11-04-2009, 09:02 PM
<?php
/*replace the $phonenumber variable with a global variable you use in your script*/

//remove dashes
$phonenumber = str_replace("-", "", $phonenumber);
//remove spaces
$phonenumber = str_replace(" ", "", $phonenumber);
//remove brackets
$phonenumber = str_replace("(", "", $phonenumber);
//remove brackets
$phonenumber = str_replace(")", "", $phonenumber);

?>

545-645-4242

would to turn into:

5456454242

traq
11-05-2009, 03:36 AM
you could do it all at once, as well


$find = array("(", ")", "-", " ");
$replace = "";
$phoneNumbers = str_replace($find, $replace, $phoneNumbers);