title: textbox only accept number when first radio button checked
body: <p>i have four radio button, i want when user click first radio button, input textbox can only accept number but if they select other radio button, number and text only can be accepted. Below is my code :</p>
  
  <pre><code>&lt;input class="form-control" type="text" id="usr_matriculation" maxlength="40" name="usr_matriculation" required="required"&gt;
  
      &lt;div class="radio"&gt;
          &lt;label class="radio-inline"&gt;&lt;input type="radio" onclick="il.Form.showSubForm('subform_usr_id_type_1', 'usr_id_type', null);" name="usr_id_type" id="usr_id_type_1" value="1"&gt;
          New Identity Card No.&lt;/label&gt;
  
      &lt;/div&gt;
  
  
      &lt;div class="radio"&gt;
          &lt;label class="radio-inline"&gt;&lt;input type="radio" onclick="il.Form.showSubForm('subform_usr_id_type_2', 'usr_id_type', null);" name="usr_id_type" id="usr_id_type_2" value="2"&gt;
          Passport No.&lt;/label&gt;
  
      &lt;/div&gt;
  
  
      &lt;div class="radio"&gt;
          &lt;label class="radio-inline"&gt;&lt;input type="radio" onclick="il.Form.showSubForm('subform_usr_id_type_3', 'usr_id_type', null);" name="usr_id_type" id="usr_id_type_3" value="3"&gt;
          Army No.&lt;/label&gt;
  
      &lt;/div&gt;
  
  
      &lt;div class="radio"&gt;
          &lt;label class="radio-inline"&gt;&lt;input type="radio" onclick="il.Form.showSubForm('subform_usr_id_type_4', 'usr_id_type', null);" name="usr_id_type" id="usr_id_type_4" value="4"&gt;
          Police No.&lt;/label&gt;
  
      &lt;/div&gt;
  </code></pre>
  
  <p>i try use below code but when i select other radio button, i cannot type text need to put number only. do i need to put if else? i need it auto change without refresh the page.</p>
  
  <pre><code>$('#usr_id_type_1').click(function() {
        alert("1");
  
      $('input[name="usr_matriculation"]').keyup(function(e)
                                      {
        if (/\D/g.test(this.value))
        {
          // Filter non-digits from input value.
          this.value = this.value.replace(/\D/g, '');
        }
      });
      });
  </code></pre>
  
  <p>my fiddle : <a href="https://jsfiddle.net/designblog4u/yock8zdw/" rel="nofollow noreferrer">https://jsfiddle.net/designblog4u/yock8zdw/</a></p>