PHP正则表达式无法正常工作

So I am trying to validate phone numbers with the form xxx-xxx-xxxx where x is a digit. The problem I am having is I can enter more than 4 digits for the last group of numbers. Does anyone see what I am doing wrong? Thanks.

    $telNumPattern = '/[0-9]{3}-[0-9]{3}-[0-9]{4}/'; //regular expression to match xxx-xxx-xxxx
    if(empty($_POST['telNum'])) {
        $errors['telNum'] = "*Your telephone number can't be empty";
    }
    else if(!preg_match($telNumPattern, $_POST['telNum'])) {
        $errors['telNum'] = "*Your email must be in the form xxx-xxx-xxxx";
    }
$telNumPattern = '/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/';

Use anchors to make an exact match.

Try this its working :

$telNumPattern = '/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/'; //regular expression to match xxx-xxx-xxxx
    if(empty($_POST['telNum'])) {
        $errors['telNum'] = "*Your telephone number can't be empty";
    }
    else if(!preg_match($telNumPattern, $_POST['telNum'])) {
        $errors['telNum'] = "*Your email must be in the form xxx-xxx-xxxx";
    }