I am trying to set max length in the input number field, but it nor working. I just set a max number in input number file, I am trying with this code:
<input type="number" name="quantity" min="1" max="99999">
This code not working for set max length, I want to set input number max length using jquery. How can I do it?
To set max length of input number in jQuery, apply these example code:
<script type="text/javascript"> $(document).on("change paste keyup",'#myInput' ,function(e) { var text=$(this).val(); if (!$(this).val() || (parseInt($(this).val()) <= 99999 && parseInt($(this).val()) >= 0)) $(this).data("old", $(this).val()); if (!$(this).val() || (parseFloat($(this).val()) <= 99999 && parseFloat($(this).val()) >= 0)){ return true; }else{ $(this).val($(this).data("old")); } }); </script>
Input type number:
<input type="number" id="myInput" />
Don’t forget to apply jquery.min.js link while you are working with jQuery. You can copy the belod code to set jquery.min.js CDN link.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
Question and answer is powered by AnsPress.io