javascript - textbox take only numeric value and not take zero at the starting -


i new in javascript , want validate textbox javascript.textbox should take numeric value , should not take 0 @ starting.

i tried below function works fine not understand how avoid 0 first position.

below html code.

<asp:textbox id="cp1_txtmob" palceholder="10 digit mobile no." ondrop="return false;" onpaste="return false;" runat="server" class="textfile_new2" style="color: #333;" onkeydown="return isnumberkey(event);"  maxlength="10" autocomplete="off"></asp:textbox>  function isnumberkey(e) {     var t = e.which ? e.which : event.keycode;     if ((t >= 48 && t <= 57) || (t >= 96 && t <= 105) || (t == 8 || t == 9 || t == 127 || t == 37 || t == 39 || t == 46))         return true;     return false; } 

please me out.

you can use onkeyup="avoidzero(this.id);" like

<asp:textbox id="cp1_txtmob" palceholder="10 digit mobile no." ondrop="return false;" onpaste="return false;" runat="server" class="textfile_new2" style="color: #333;" onkeydown="return isnumberkey(event);"  maxlength="10" autocomplete="off" onkeyup="avoidzero(this.id);"></asp:textbox>  function avoidzero(v) {      var v = document.getelementbyid(v).value;          return (v.charat(0) == 0) ? (document.getelementbyid(v).value = v.substring(1, v.length), false) : false;  } 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -