Telephone Number Validation

I want to validate a number posted into a variable from a html form.


      $dest1; = $_REQUEST["mobile"];

So a html form posts the mobile number into the variable dest1


I then need it to check/modify dest1 so it looks like - 447525000000

Rather than the standard - 07525000000


Then post the checked/modified number into variable dest2

I have never used PHP before, I am sure this is very simple but I need it ASAP :-)

Thanks In advance!

Ben

souldigitalAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cr4ck3rj4ckCommented:
Hey there,

The code below drops the leading 0, if present, and prepends 44. Otherwise it outputs identical to $dest1.

Hope that helps,
CJ
<?php
$dest1 = $_REQUEST["mobile"];
$dest2 = (substr($dest1,0,1) == '0') ? '44'.substr($dest1,1) : $dest1;
echo $dest2;
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
souldigitalAuthor Commented:
That's great thanks! Is there any way of telling it to drop +44 if entered and replace it with just 44 as well?

Also is it possible to remove gaps, for example if someone entered -

07 525 000000

it would turn it into

447525867821

Thanks!

Ben
0
James LooneySr. Programmer/AnalystCommented:
to strip whitespace, you could do a number of different things:



$number = str_replace(" ", "", $_REQUEST["mobile"]);
 
or
 
$number = preg_replace('/\s+/', '', $_REQUEST["mobile"]);

Open in new window

0
souldigitalAuthor Commented:
That works great!

Thanks guys!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.