Jump to content

preg_match problem


BrettCarr

Recommended Posts

Hi Guys im trying to do a preg_match on a phone number, when i type the pattern in the code it works fine but when i parse to preg_match in a variable it refuses to worrk here is my code below

 

<?php
$cc = '61';
$ac = '4';
$ph = '8';
$ext = '/0/';

$phoneNumber = '610415676836';
//ok try this
$pattern = "'/^$cc([$ac]{1})([0-9]{{$ph}})$/'";

echo $pattern."<br />";
$numlen = strlen($phoneNumber);
if($numlen = 12){
    $phoneNumber1 = preg_replace($ext,'',substr($phoneNumber,3));
    //echo $phoneNumber1;
    $phoneNumberComplete = $cc.$phoneNumber1;
   echo $phoneNumberComplete."<br />";
}
if(preg_match($pattern, $phoneNumberComplete))// this doen't seem to work
{
    echo "Oh yeh";
} else {
    echo "boo hiss";
}

if(preg_match('/^61[4]{1}[0-9]{8}$/', $phoneNumberComplete))// this does work
{
    echo 'is true';
} else {
    echo "not doing it";
}
//please help

?>

Link to comment
https://forums.phpfreaks.com/topic/245174-preg_match-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.