title: jquery Change input mask template based on value length
body: <p><br>
  I cannot figure out how to change the input template mask based on value length. <br><br>
  For example: I have two car number templates '99-999-99' and '999-99-999'. I need to change the input mask based on value length. <br><br>
  If value length is 7 or smaller, the template must be '99-999-99'. If value length is bigger then 7, the temple must be '999-99-999'. </p>
  
  <p>My code: </p>
  
  <pre><code>$("#carnum").keyup(()=&gt;{
    var masks = ['99-999-99', '999-99-999'];
    var value = $('#carnum').val().replace(/-/g, '');
    value.length &lt;= 7 ? -1 :  $('#carnum').mask(masks[1]);
  })
  $("#carnum").mask('99-999-99');
  </code></pre>
  
  <p>Here is the <a href="http://jsfiddle.net/alikchebotar/4m0uLxfs/4/" rel="nofollow noreferrer">fiddle</a>.</p>
  
  <p>Thank you!</p>