For <input type="number">
element, maxlength
is not working. How can I restrict the maxlength
for that number element?
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a way to play audio on a mobile browser w
- HTML form is not sending $_POST values
- implementing html5 drag and drop photos with knock
-
Why does the box-shadow property not apply to a
Max length will not work with
<input type="number"
the best way i know is to useoninput
event to limit the maxlength. Please see the below code for simple implementation.simple way to set maxlength for number inputs is:
HTML Input
jQuery
As I found out you cannot use any of
onkeydown
,onkeypress
oronkeyup
events for a complete solution including mobile browsers. By the wayonkeypress
is deprecated and not present anymore in chrome/opera for android (see: UI Events W3C Working Draft, 04 August 2016).I figured out a solution using the
oninput
event only. You may have to do additional number checking as required such as negative/positive sign or decimal and thousand separators and the like but as a start the following should suffice:I would also recommend to combine
maxlength
withmin
andmax
to prevent wrong submits as stated above several times.