Weird jQuery errors on character counter
<p>I'm trying to make a simple character counter which shows whether the user has typed in the minimum number of characters before they can press enter.</p>

<pre><code>$(document).ready(function(){

 $('#notification').hide();
 $('#press_enter_notification').hide();  

   var allow_enter = false;
   var min = 4;
   var max = 30;
   var char_count = 0;

   $("#form_textbox").keydown(function() {

      $('#press_enter_notification').hide();  

      if(this.value.length &lt; min) {
         char_count = min - (this.value.length) -1;
         //alert('Too short');
         $('#notification').show("fast");
         $('#notification').text(char_count + ' more characters to go');
         allow_enter = false;

      } else if(this.value.length &gt;= max) {
         char_count = (this.value.length) - max;
         this.value = this.value.substring(0,max);
         $('#notification').show("fast");
         $('#notification').text(' no more characters remaining');

      } else {
         char_count = max - (this.value.length) -1;
         $('#notification').show("fast");
         $('#notification').text(char_count + ' characters remaining');
         $('#press_enter_notification').show("fast");
         allow_enter = true;
      }   
   });

   $("form").submit( function () {
      if (allow_enter == false)
      {
         $('#press_enter_notification').show("fast").text('you cannot press enter yet');
         return allow_enter;
      }  
   } );


});  
</code></pre>

<p>It works, however it has the following quirks:</p>

<ol>
<li>When you type something in and delete all the text, the character count message doesnt dissapear, or count backwards</li>
<li>When you delete everything it says 3 more characters to go, I had to add -1 at <code>if(this.value.length &lt; min) {
         char_count = min - (this.value.length) -1;</code>, otherwise it lets you enter 5 characters before it stops saying 3,2,1 more characters to go.</li>
</ol>

<p>If you try this out in a browser or jsbin you will notice them. How can I structure this to sort it?</p>

<p>Thank you.</p>
