input control can only enter numbers

Only when they want to enter numbers with input and limit the length  

A first input digital not only limit the length:

onkeyup = "value=value.replace(/[^\d]/g,'')"

The second and only limit the length of the input digital:

oninput="if(value.length>1)value=value.slice(1,10)" 

Such as the need phone number phone number is 11

So the (value.length> 1) read (value.length> 11) in the (value.slice (1,10)) changed (value.slice (0,11)) will be the longest 11 digits 

Explanation:

(Value.length> maximum number)

Explanation:

(Value.slice (minimum input, maximum input))

Input box Enter the precautionary statements precautionary statements disappear when filled out:

placeholder = "Please enter the content you want to fill"

 

Guess you like

Origin www.cnblogs.com/yutang-wangweisong/p/12666128.html