title: Input alters text box format
body: <p>I am new to JavaScript and I have been doing some work creating a form in HTML and JavaScript. In this work I have been trying to validate the format of an input depending on the text entered into a previous field.</p>
  
  <p>What i have been trying is if the country 'Australia' is entered into the 'Country' text box than the 'Telephone' text box is limited to the format (00)00000000 and if it is any other country than the 'Telephone' text box must be formatted in the international number way including the + and country code following e.g. +61 etc</p>
  
  <p>i have done this much of a function so far:</p>
  
  <pre><code>&lt;script&gt;
  document.getElementById('txttelephone').onchange = function()
  {
  var num1 = document.getElementById('txttelephone').value,
      country = document.getElementById('txtcountry').value,
      regex;
  
  if (country == "Australia" || country == "australia")
  {
      regex = /\(\d{2}\)\d{8}/;
  }
  else
  {
      regex = /\+\d{15}/;
  }
  if (!num1.match(regex))
  {
      alert('That is not a correct telephone number');
  }
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>That is just the function i did to limit the string length of the 'Telephone' text box to 12 characters but i still have yet to validate to make sure that the area code is included in between brackets in the the form of (00)00000000 and also to validate that a + is included if the country is anything other than Australia (international numbers including country codes).</p>
  
  <p>Here is the HTML i have to use the function on:</p>
  
  <pre><code>&lt;b&gt;Country:&lt;/b&gt; &lt;input type="text" id="txtcountry" name="country"&gt;
  &lt;br&gt;
  &lt;b&gt;Telephone:&lt;/b&gt; &lt;input type="text" id="txttelephone" name="telephone"&gt;
  </code></pre>
  
  <p>Any help would be greatly appreciated!</p>