I am trying to format number through jQuery in USA phone number format. that is (111) 111 1111 but it doesn't let me delete also it is adding 11th digit and not deleting it. Can anyone help?
$("#no").keypress(function(e) { var value = $(this).val(); if(value.length <= 10) { var first = "(" + value[0]+value[1]+value[2] + ")" + " " + value[3]+value[4]+value[5]+ " " + value[6]+value[7]+value[8]+value[9]; $(this).val(first); $("#no_span").html(first); e.preventDefault(); } if(value.length > 10) { $(this).val($("#no_span").html()); } }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input id="no" maxlimit="14"/> <span id="no_span"></span>