Validate zip and display error with onBlur event
<p>Check if zip is 5 digit number, if not then display 'zip is invalid'. I want to use onBlur event to trigger the display. But it's not working.  </p>

<pre><code>&lt;script&gt;
$(function(){

function valid_zip()
  {
  var pat=/^[0-9]{5}$/;
  if ( !pat.test(   $('#zip').val()   ) )
     {$('#zip').after('&lt;p&gt;zip is invalid&lt;/p&gt;');}
  }

})
&lt;/script&gt;

zip (US only) &lt;input type="text" name='zip' id='zip' maxlength="5" onblur="valid_zip()"&gt;
</code></pre>
