Is there any way to prevent input type=“number” getting more than one dot values?
问题 I want to get only decimal values like 1.5,0.56 etc. but its allowing more than one dot. is there any way to prevent it 回答1: You can use pattern attribute: <input type="text" pattern="[0-9]+([\.,][0-9]+)?"> It will allow patterns with a single dot, or even a comma (european decimals for example). To remove the comma, should be: <input type="text" pattern="[0-9]+([\.][0-9]+)?"> 回答2: Originally shared here You can find very detailed explainations in this Codepen This solution is simple and will