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