[英]How to allow user to type in certain number of input value before decimal and certain number of input value after decimal
輸入的類型只能是數字和退格鍵,應允許使用del。 示例-小數點前的3個數字和小數點后的2個數字應僅允許我們輸入以下類型的內容-
你的意思是這樣的嗎?
const input = document.querySelector(".enforce-pattern"); input.oninput = input.onchange = function(){ input.value = input.value.match(/^\\d{0,3}(?:\\.\\d{0,2})?/); };
<input class="enforce-pattern" type="text">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.