mardi 25 avril 2017

Conditional statement for checking input digit is 8 or 6 digit

I have following code for, checking whether the input number is;

  1. Empty or not.
  2. is number or not.
  3. is 8 digit or not.

But cant figure out. If the input is not 8 or 6 digit, it suppose to give error.

if ($_POST['phone']==''){
        $has_errors=true;
        $errors[]=__('Phone field is empty','wpestate'); 
    }
        else if(!is_numeric($_POST['phone'])) {
           $has_errors=true;
           $errors[]=__('Phone number entered was not numeric','wpestate'); 
        } else if(strlen($_POST['phone']) != 8) {
           $has_errors=true;
           $errors[]=__('The number entered was not 8 digits long','wpestate'); 
        } 

Aucun commentaire:

Enregistrer un commentaire