javascript - Number only input box with range restriction -


i know can use <input type="number"> restrict text box integer input. however, wondering if there possibility of range restricting well? limiting factor being without using javascript function check on every keyup. seems little heavy , unnecessary. think html5 have built in take care of edge-case, haven't been able find anything.

for example, have input box deduplication ratio want restrict user inputting numbers (integer or float) between 3 , 7.

i have option-select dropdown whole , half numbers, not provide level of detail i'm looking for.

as mentioned in comments earlier... there isn't html here (you'd think there should be). but... since did include javascript , jquery in question, i'll propose simple , light solution.

assuming html...

<form>   <input type="number" min="3" max="7" step="0.5"></input> </form> 

then can use script handle our requirements.

$( document ).ready(function() {     $('input').change(function() {       var n = $('input').val();       if (n < 3)         $('input').val(3);       if (n > 7)         $('input').val(7);     }); }); 

basically, after change event fires, quick check make sure values within guidelines, , if not, force them within range.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -