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();     } }); 

jsfiddle


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -