validate datefield without using datepicker

validate datefield without using datepicker

Hello,

Thanks to all who have previously helped me.  
I have a weird situation.  I'm using a text field for the date in a form but not using datepicker because I have not been able to get it to work with a screen reader.  This script I'm using below, works in jsfiddle but on my page allows 5 digits for the year instead of only 4.

Any ideas pointing me in the right direction are appreciated.

  1. $(document).ready(function() {
  2. $("input[name='date1']").keyup(function(e){
  3. var key=String.fromCharCode(e.keyCode);
  4. if(!(key>=0&&key<=9))$(this).val($(this).val().substr(0,$(this).val().length-1));
  5. var value=$(this).val();
  6. if(value.length==2||value.length==5)$(this).val($(this).val()+'/');
  7. });
  8. });

Thanks
Peter T