title: A regex to allow exactly 5 digit number with one optional white space before and after the number?
body: <p>With the regex in the jQuery code below, I can restrict the input text field to accept only 5 digits but it allows more white spaces before and after the number than just one. I mean to match a 5-digit number that is at the beginning of the string or is preceded by at most one space and is at the end of the string or is followed by at most one space. Please help me refine my regex to meet my requirement.</p>
  <pre><code>jQuery(&quot;input:text[name='address_1[zip]']&quot;).change(function(e) {
  if (!jQuery(this).val().match(/\b\d{5}\b/g)) { 
          alert(&quot;Please enter a valid zip code&quot;);
          jQuery(&quot;input[name='address_1[zip]']&quot;).val(&quot;&quot;);
          return false;                        
      }        
  });
  </code></pre>