BrettCarr Posted August 19, 2011 Share Posted August 19, 2011 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/245174-preg_match-problem/ Share on other sites More sharing options...
btherl Posted August 19, 2011 Share Posted August 19, 2011 Try like this: $pattern = "/^$cc([$ac]{1})([0-9]{{$ph}})$/"; Quote Link to comment https://forums.phpfreaks.com/topic/245174-preg_match-problem/#findComment-1259288 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.