International Mobile Numbers

15 posts by 3 authors in: Forums > CMS Builder
Last Post: January 31, 2011   (RSS)

By Toledoh - January 28, 2011

HI Jason,

Attached is the profile.php

It's making sure the input is correct (ie. starts with 04) but doesn't convert it to the international format.

NB. The is an error on this file re membership checkboxes - but that's another discussion)

Cheers,
Tim
Cheers,

Tim (toledoh.com.au)
Attachments:

profile_006.php 10K

Re: [Toledoh] International Mobile Numbers

By Jason - January 28, 2011

Hi Tim,

There was a small error in the function, try replacing it with this:

// Mobile Number Format
function format_mobile_number($mobile){
//strip out spaces
$mobile = str_replace(" ","",$mobile);
$tmpPhone = str_split($mobile);

if(@$tmpPhone[1]==4){

$tmpPhone[0]=61;
$phone=implode($tmpPhone);
}
else{
//error
return false;
}
return $phone;
}


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Toledoh] International Mobile Numbers

By Jason - January 31, 2011 - edited: January 31, 2011

Hi Tim,

Here's a new version of the format_mobile_number function.

// converts a "04" mobile number to a "614" mobile number
function format_mobile_number($mobile){

//strip out spaces
$tmpPhone = str_replace(" ","",$mobile);
$tmpPhone = str_split($tmpPhone);

if(@$tmpPhone[1]==4){ //number is in the local format. Convert it to international format

$tmpPhone[0]=61;

$phone=implode($tmpPhone);
}
elseif(@$tmpPhone[0]==6 && @$tmpPhone[1]==1 && @$tmpPhone[2]==4){ //number is in international format. Return it as is.

$phone = implode($tmpPhone);
}
else{ //error. The number is in an invalid format.

return false;
}

return $phone;
}


In this version, if you send it a number in the format "04" it will convert it to a "614" format. If you pass it a "614" format, it will just give it back to you without changing it. If it's given a different format, it sends back "false" to indicate an error.

In addition, you could save two different mobile numbers in the database. You can store 1 they way they entered it, and then store the formatted one in a different field.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By Toledoh - January 31, 2011

Woo Hoo!

Thanks!
Cheers,

Tim (toledoh.com.au)