For text-based inputs such as <input type="text"> or <input type="number">, you can use the maxlength attribute to restrict the number of digits in an HTML input field. This limits the user's ability to enter a maximum of characters. For example, to limit input to 10 digits:
<input type="number" maxlength="10">
If you want to restrict the input specifically to a certain number of digits in a number input field, you can use the max attribute along with a regex pattern. This is useful for enforcing specific formats, such as limiting input to a 5-digit number:
<input type="number" max="99999" pattern="\d{5}">