One of my weaknesses has always been pattern matching. Something I
definitely need to study up on and maybe you guys can give me a pointer
here.
I'm looking to remove all of this code and just use pattern matching to
determine if the proper amount of numeric characters has been met. Here is
the function I've already done. Any help you can give in a pattern matching
solution would be much appreciated and very educational.
//the $area option is for determining if the user need (or need not) type in
their area code.
function check_phone($ph one,$area='y'){
if($area=='y'){
$min=10;
} else {
$min=7;
}
//is there a more direct approach to just count the amount of numbers in
the string by pattern matching?
$phone=str_repl ace('-','',$phone);
$phone=str_repl ace('(','',$pho ne);
$phone=str_repl ace(')','',$pho ne);
$phone=str_repl ace(' ','',$phone);
if(!preg_match( '/[\d]{'.$min.',}/',$phone)){
return(FALSE);
} else {
return(TRUE);
}
}
definitely need to study up on and maybe you guys can give me a pointer
here.
I'm looking to remove all of this code and just use pattern matching to
determine if the proper amount of numeric characters has been met. Here is
the function I've already done. Any help you can give in a pattern matching
solution would be much appreciated and very educational.
//the $area option is for determining if the user need (or need not) type in
their area code.
function check_phone($ph one,$area='y'){
if($area=='y'){
$min=10;
} else {
$min=7;
}
//is there a more direct approach to just count the amount of numbers in
the string by pattern matching?
$phone=str_repl ace('-','',$phone);
$phone=str_repl ace('(','',$pho ne);
$phone=str_repl ace(')','',$pho ne);
$phone=str_repl ace(' ','',$phone);
if(!preg_match( '/[\d]{'.$min.',}/',$phone)){
return(FALSE);
} else {
return(TRUE);
}
}
Comment