title: Issue on Using Regular Expression in PHP Simple Validation
body: <p>I am trying to learn Regular Expression in PHP by creating simple samples.Here I have very simple example as:
         
  
  <pre><code>if($_POST){
     $errors = array();
  
    if(isset($_POST['name'])){
       if(!preg_match('/^([a-zA-Z]{3,8})$/',$_POST['name'])){
         $errors['name1'] = "Must enter Alphabet";
         $errors['name2'] = ""Cant be less than 3";
       }
  
    }
    if(count($errors)==0){
    header("Location: pro.php");
    exit();
    }
  }
  ?&gt;
  
  &lt;form method="POST" target=""&gt;
  First name: &lt;input type="text" name="name"&gt;&lt;br&gt;
  &lt;input type="submit" name="submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>To me, the validation is working fine but I have problem on presenting error message based on error.For example I would like to display error <code>$errors['name1']</code> ONLY when not string has entered and <code>$errors['name2']</code> while numbers entered.
  I tried to separate expression into two criteria as:</p>
  
  <pre><code>if(isset($_POST['name']))
     {
       if(!preg_match('/^([a-zA-Z])$/',$_POST['name']))
       {
         $errors['name1'] = "Must enter Alphabet";
       }
        if(preg_match('/^{3,8}$/',$_POST['name']))
       {
         $errors['name2'] = "Cant be less than 3";
       }
     }
  </code></pre>
  
  <p>but I am getting following error 
  <img src="https://i.stack.imgur.com/jaaOI.png" alt="enter image description here"></p>
  
  <p><strong>Update</strong></p>
  
  <pre><code>if(isset($_POST['name']))
     {
       if(!preg_match('/^([a-zA-Z])$/',$_POST['name']))
       {
         $errors['name1'] = "Must enter Alphabet";
       }
        if ( ! preg_match( '/.{3,8}/', $_POST['name'] ))
       {
         $errors['name2'] = "Cant be less than 3";
       }
     }
  </code></pre>