0

I have one textbox which is of number type. I want it to accept maximum of 16 digits, not more than that. For that I have tried with "maxlength" attribue and "max" attribute both. But its not working. Can anyone provide me solution?

<input type="number" id="dummy" max="16" />

Edit: I need to enter only whole number since it is used for account number of bank.

Teddu
  • 207
  • 6
  • 18
  • Please define "its not working". – Teemu Sep 12 '16 at 09:09
  • And be more specific about what you want to allow. Only whole numbers? Up to 16 digits left of the decimal? Right of it? A total of 16 regardless of where the decimal is? Or 15 plus the decimal? (E.g., are you trying to *very roughly* avoid precision issues with IEEE-754 double-precision floating point values?) – T.J. Crowder Sep 12 '16 at 09:13
  • 1
    Have look at this reference http://stackoverflow.com/questions/8354975/how-to-add-maxlength-for-html5-input-type-number-element – Sasikumar Sep 12 '16 at 09:13
  • If you only care about whole numbers, see the question Sasikumar linked above. – T.J. Crowder Sep 12 '16 at 09:22

2 Answers2

0

There are a few of these "how do I further control type="number" fields" questions here on SO. It boils down to:

  1. You make it a type="number" and accept that you can't further mask the input vs. what the browser does to implement a numeric input, or

  2. You make it type="text" and use pattern and/or maxlength to enforce the specific pattern you want, and accept that the browser won't add a specific UI for numbers.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
-1

Input type number doesn't support "maxlength" attribute. You can specify "max" attribute (HTML5), which is the highest number user can input. Something like this: <input type="number" max="999999999999" id="dummy" step="1" min="0">. Edit: Also specify step attribute to 1.

Paulooze
  • 1,147
  • 10
  • 13