-1

I am trying to achieve user can only enter 10 numbers in input, also if the user put let's say 5 numbers that are also not allowed, so min and max should be 10.

<input type="number" min="10" max="10" >

Can anybody try to help me with this?

Mihalma
  • 91
  • 1
  • 8
  • 1
    `minlength` and `maxlength` are not valid attributes on a number input. Did you mean `min` and `max`? You seem to want to restrict the length of the number, so maybe the number input type is not what you need? Try using the text input type instead? – evolutionxbox Feb 24 '21 at 12:54
  • 1
    If the min and max values are 10, you could enter only 10 to the input. Can you please describe the conditions a bit more accurately? – Teemu Feb 24 '21 at 12:56
  • I think where OP says '10 numbers', they mean '10 digits'. – Peter B Feb 24 '21 at 12:57
  • @Teemu, yes, can try to enter 50 number in my input, and you will see that input is not limited to 10 numbers? – Mihalma Feb 24 '21 at 12:57
  • @Mihalma the number input does not have the ability to restrict the length of a number. Why are you wanting to do this? Perhaps if we know the reason we can suggest a better approach – evolutionxbox Feb 24 '21 at 12:57
  • 1
    Does this answer your question? [How can I limit possible inputs in a HTML5 "number" element?](https://stackoverflow.com/questions/8354975/how-can-i-limit-possible-inputs-in-a-html5-number-element) – evolutionxbox Feb 24 '21 at 13:01

1 Answers1

0

minlength and maxlength attributes don't exist. Instead, use min and max. I understand you want a 10 digits input only, so you should be doing:

<input type="number" min="1000000000" max="9999999999">
evolutionxbox
  • 3,932
  • 6
  • 34
  • 51
corbin-c
  • 669
  • 8
  • 20