/    Sign up×
Community /Pin to ProfileBookmark

Setting a limit on the maximum number of input fields

Hello,
I want to allow only numbers from 0 to 45 in the input field, not characters.
Must have number entry permissions such as 5.05, 8.75

This code allows input of number in 0.00 format and how to set input limit of number from 0.00 to 45.00

“`
$(“#id-name”).on(‘blur change input’, function () {
$(this).val(function (i, input) {
input = input.replace(/D/g, ”);
return (input / 100).toFixed(2);
});
}).trigger(‘blur’);
“`

how do i do this
can you help me
Thank you

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumNov 13.2021 — This can be done easily without javascript by use of an input of type "number":

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number
Copy linkTweet thisAlerts:
@gecekuleauthorNov 13.2021 — I looked at the page you gave, but couldn't find anything that would work for me.

I don't fully understand as I don't know javascript.

Can you help more clearly?

Maybe I asked the wrong question

I want to allow the input of the number 0 to 45

or 44.58 could be the limit

I want to allow number inputs like 0.01, 0.50, 10.50, 24.80

But the limit can be 50.26

I want it to work from keyboard and mobile
Copy linkTweet thisAlerts:
@SempervivumNov 13.2021 — Number input doesn't require javascript. Just add the attributes min, max and step like this:

`&lt;input id="test-number-input" type="number" min="0" max="50" step="0.01"&gt;</C><br/>
When you confirm the input by pressing enter an error window will be displayed in case the format is wrong.<br/>
By adding a bit of CSS the appearance can be changed immediately:
<CODE>
`<i>
</i> &lt;style&gt;
#test-number-input:invalid {
color: red;
}
&lt;/style&gt;<i>
</i>
``
Copy linkTweet thisAlerts:
@gecekuleauthorNov 14.2021 — Thank you

I get it now
×

Success!

Help @gecekule spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...