title: HTML input field restricted with regular expression pattern
body: <p>I want to restrict the user input in an HTML input field.</p>
  
  <p>It is a field which accepts the weight in decimal and the unit(kg, lbs, g, t etc).</p>
  
  <p>Following are few sample input which are valid:</p>
  
  <pre><code>10.45 kg
  125.5 kg
  120.35 lbs
  160 lbs
  1200.16 g
  24.6 t
  </code></pre>
  
  <p>I am using the JQuery plugin mentioned in the below URL:
  <a href="http://www.thimbleopensource.com/tutorials-snippets/jquery-plugin-filter-text-input" rel="nofollow">http://www.thimbleopensource.com/tutorials-snippets/jquery-plugin-filter-text-input</a></p>
  
  <p>But it is not working with complex patterns.
  Can anyone please help me with the regular expression to achieve the result?</p>
  
  <p>Find the complete code below:</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Test&lt;/title&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
  
  &lt;script src="/js/jquery/jquery-2.1.4.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="/js/jquery/jquery.filter_input.js" type="text/javascript"&gt;&lt;/script&gt;
  
  &lt;script type="text/javascript"&gt;
  &lt;!--//
  
  $(document).ready(function(){
     $('#input_2').filter_input({ regex: '\d+(?:.\d+)?\s(?:kg|lbs|t)' });
  });
  
  //--&gt;
  &lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
  
  Weight: &lt;input id="input_2" type="text" size="20" /&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>