Home > Enterprise >  How can I prevent trailing periods in number inputs?
How can I prevent trailing periods in number inputs?

Time:05-03

I have the following HTML that prevents everything to be entered in a number search field, except for an ending period:

<input type="number" id="DrawingNumber" min="1" oninput="validity.valid||(value='');" />

For example, I can enter "1." or "111." etc. I would like it to prevent me from entering the ending period. It prevents me from entering everything else, such as leading zeroes, symbols, letters, except for the ending period.

CodePudding user response:

<input type="number" id="DrawingNumber" 
       min="1" 
       onkeypress="return /\d/i.test(event.key)"
       oninput="validity.valid||(value='');" />

  • Related