title: Phone number validation with jQuery
body: <p>I have this really cool validation script for entering currency which I love</p>
  
  <p><a href="https://jsfiddle.net/938ewm3v/" rel="nofollow">Demo Currency Validator</a></p>
  
  <pre><code>$("#saleprice").on("keyup", function(){
      var valid = /^\d{0,4}(\.\d{0,2})?$/.test(this.value),
          val = this.value;
  
      if(!valid){
          console.log("Invalid input!");
          this.value = val.substring(0, val.length - 1);
      }
  });
  </code></pre>
  
  <p>But I would love to have the same thing to validate a phone number. Here is my fiddle with the regex for a phone, but I cant seem to get it to work. The code is not allowing any characters to be typed in even though I specify characters like <code>()</code> as well as numbers and <code>-</code>,<code>.</code> to be allowed in the regex.</p>
  
  <p><a href="https://jsfiddle.net/o10t9eqL/" rel="nofollow">Demo Telephone Validator</a></p>
  
  <pre><code>$("#telephone").on("keyup", function(){
      var valid = /\(?([0-9]{3})\)?([ .-]?)([0-9]{3})\2([0-9]{4})/.test(this.value),
          val = this.value;
  
      if(!valid){
          console.log("Invalid input!");
          this.value = val.substring(0, val.length - 1);
      }
  });
  </code></pre>
  
  <p>I would like to allow the following formats of a phone number.</p>
  
  <ul>
  <li>(123) 456 7899</li>
  <li>(123).456.7899</li>
  <li>(123)-456-7899</li>
  <li>123-456-7899</li>
  <li>123 456 7899</li>
  <li>1234567899</li>
  </ul>