Restricting values to a range
Closed this issue · 2 comments
Hi,
how can I ensure numeric value for e.g. Hours in a day are restricted to a decimal value, i.e. with a decimal
between 0.0
to 24.0
I am unable to let it enter the .
also will this work with jquery 3.2? looks to be 7 yrs old
Hi,
for the lower limit you can set negative values to false. There is no flag to set an upper limit, but it should be easy to implement in jquery.numeric.js. The file test.html contains some examples. What you want is perhabs something like this:
Step 1:
create your input field in html-code e.g.
<input class="your_class_name_positive_decimal_2_places" type="text" />
Step 2:
set numeric properties of your class in the js code e.g.
$(".your_class_name_positive_decimal_2_places").numeric({ decimalPlaces: 2, negative: false });
I use a slightly modified version ( see pull request #99 ). It could be interesing if you want to use an alternative decimal separator for time like "23:59". Then step 2 would look like this:
$(".your_class_name_positive_decimal_2_places").numeric({ decimalPlaces: 2, negative: false, altDecimal: ":" });
I can confirm it is working with jquery 3.2 under Firefox, Chrome and IE.
@MaRoed your suggestions were enormously helpful, but I need some help to limit the upper limit,
for e.g.
mins = 60 (with or without decimals is fine)
hour = 23:59 (with or without decimals is fine)