Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Input type number is not working with maxlength

I'm using below html tag and not able to get the restrictions on numbers, I need user to enter 12 digit only however as per HTML tag by default 'maxlength' does not work with <input type ="number">, I tried min and max tag, it did not help either.

Could you share if any way to do it in HTML only?

<input type="number" name="Aadhar" maxlength="12" placeholder="xxxx-xxxx-xxxx" pattern="[0-9]{4}-[0-9]{4}-[0-9]{4}" required>
like image 777
Amit Kumar Avatar asked Nov 15 '25 04:11

Amit Kumar


2 Answers

Max length will not work with <input type="number". Maybe you can read this click here to read more to resolve ur problem

like image 163
Choirunnisa Avatar answered Nov 17 '25 20:11

Choirunnisa


Unfortunately, maxlength attribute is not supported for inputs that are type number. Therefore, the best approach is to use JS. Please refer to the following documentation and they might provide some clarity.

  • https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefmaxlength
  • https://html.com/attributes/input-maxlength/
  • maxlength ignored for input type="number" in Chrome
like image 34
Hashan Siriwardena Avatar answered Nov 17 '25 20:11

Hashan Siriwardena



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!