I have a field that accepts the year, so I have created
input type=\"number\"
and implemented keydown event to restrict
HTML:
jQuery:
$(document).on('input', '.year', function(){ var txt = $(this).val(); if(isNaN(txt) || txt > 9999){ $(this).val( $(this).data('temp') ); return; } $(this).data('temp', txt); });
JSFiddle