₦airaland Forum

Welcome, Guest: Join Nairaland / LOGIN! / Trending / Recent / New
Stats: 2,297,194 members, 5,048,189 topics. Date: Saturday, 20 July 2019 at 05:06 PM

Phone Number Validation - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Phone Number Validation (2141 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 pcguru1(m): 2:41pm On Apr 21, 2011
My Best Advice is to use REGEXP in PHP,its far safer

(1) (Reply)

Little drops of Python from a Flask: Learn Web Programming with Python / Help With This Regular Expression: / My Third Android App

(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: (0) (1) (2) (3) (4) (5) (6) (7) (8) (9)

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