Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

About the input box Limits the input length record


May 30, 2021 Article blog


Table of contents


Description of the problem: Input input box length limit - non-regular expression

Way one

type = "number"  -> 输入类型

oninput ->{

oninput 事件在用户输入时触发。

该事件在 <input> 或 <textarea> 元素的值发生改变时触发。

提示: 该事件类似于 onchange 事件。不同之处在于 oninput 事件在元素值发生变化是立即触发, onchange 在元素失去焦点时触发。另外一点不同是 onchange 事件也可以作用于 <keygen> 和 <select> 元素

}
value.slice(start,end)

return ' <input type="number" value="'+value+'" οninput="if(value.length>16)value=value.slice(0,3)" />';
parameter description
start need. S pecify where to start. I f it is a negative number, it specifies the position from the end of the array. That is, -1 refers to the last element, -2 refers to the penultimate element, and so on.
end Optional. S pecify where to end the selection. T his parameter is the array subscript at the end of the array fragment. I f the parameter is not specified, the sliced array contains all the elements from start to the end of the array. If this argument is negative, it specifies elements that are calculated from the end of the array.

Note: If end is not specified, the slice() method picks all elements from start to the end of the array.

Specific usage please go to the official website to learn!

Mode two

maxlength属性 ->
{
maxlength 属性规定输入字段的最大长度,以字符个数计。

maxlength 属性与 <input type="text"> 或 <input type="password"> 配合使用
}
return ' <input type="number" value="'+value+'" maxlength = “长度” />';