Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,120 members, 7,818,363 topics. Date: Sunday, 05 May 2024 at 01:40 PM

Phone Number Validation - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Phone Number Validation (3880 Views)

Download All Phone Number Generator, Imei Tweaking And Bb Imei Gen. For Pc / Adding Validation To Javascript Code / [MOD] PHP Workouts-email Validation In Php Using Any Method. (2) (3) (4)

(1) (Reply) (Go Down)

Phone Number Validation by sunej(m): 9:25am On Apr 17, 2011
Please I want to validate phone numbers so my script can send sms. The numbers are in local format like 08032537302 but I want to format them to international format 2348032537302.
Please help!

Am using PHP
Re: Phone Number Validation by dellnet: 8:44am On Apr 18, 2011

$phone_num = "08032537302";
$intl_format = substr($phone_num, 1); //returns 8032537302
//now add 234 to intl_format
$intl_format = sprintf("%s%s", "234", $intl_format);
//echo $intl_format;
Re: Phone Number Validation by hustinken: 10:49am On Apr 18, 2011
<?
//use the below script

$mobile_no="08055303653";

//strip out the first 0 and replace it with 234

$new_mobile=substr_replace($mobile_no,'234','0','-10');

echo $new_mobile;

//it works

?>
Re: Phone Number Validation by wavemaster(m): 5:16pm On Apr 19, 2011
Or you can try this:

<?php
$phone= '07062999765';

// Remove initial "0" if the phone number starts with zero
if(substr($phone, 0, 1)== 0) {
$phone= substr($phone, 1);
}
// Now you can insert 234 at the beginning if it does not start with 234
if(substr($phone, 0, 3)!= 234) {
$phone= '234'.$phone;
}

// Have a nice day
?>

1 Like

Re: Phone Number Validation by Nobody: 2:41pm On Apr 21, 2011
My Best Advice is to use REGEXP in PHP,its far safer

(1) (Reply)

Chemistry! Help A Brother To Solve These Questions / Please Read / How To Be A Hacker

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 8
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.