jquery focus on mobile field till reaches max length -
i need restrict mobile number field, not loose focus till reaches max length.
suppose, if click on tab after entering numbers, example, 3 numbers, should not focus out.
i tried in following way, working mobile number field blank , not able enter character in field
jquery
$(document).on('keydown','.mobile-verified', function(e){ if($('.mobile-verified').val().length>9 && e.which==9){ //working code } else{ $(this).focus(); return false; } });
template
<input name="mobilenum" class="mobnum mobile-verified" maxlength="10" type="text">
prevent default tabbing behaviour if length of input value less maxlength
property:
$(document).on('keydown','.mobile-verified', function(e){ if (e.which == 9 && $(this).val().length < this.maxlength) { e.preventdefault(); } });
Comments
Post a Comment