title: jquery Input field pattern
body: <p>I am new to JQUERY. I have an requirement like based on the input, the same input field needs to be altered without submitting the form.</p>
  
  <p>If number starts with 33 or 55 or 81, display as (xx) xxxx-xxxx, for everything other number pattern should be (xxx) xxx-xxxx.</p>
  
  <p>Could anyone help me on this.</p>
  
  <p>I tried this code:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script src="jquery-1.11.3.min.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="jquery.maskedinput.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;h1&gt;Validation&lt;/h1&gt;
  
  &lt;input id="phone" type="number"&gt;
  &lt;script&gt;
  $(document).ready(function(){
      var twoNumbers = $(this).attr("phone").substr(0, 2);
      if(twoNumbers == 33 || twoNumbers == 55 || twoNumbers == 81){
          $("#phone").mask("(99) 9999-9999");
      }else{
          $("#phone").mask("(999) 999-9999");
      }
  });
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>
  
  <p>Please correct this html</p>