只能輸入數字和小數點的正則
<
input
type="text" autocomplete="off" id="price" autofocus="autofocus" onkeyup="value=value.replace(/[^\d^\.]+/g,'')">
onkeyup="value=value.replace(/[^\-?\d.]/g,'')" 僅允許輸入:正負小數。
<input type=
"text"
autocomplete=
"off"
id=
"price"
autofocus=
"autofocus"
onkeyup=
"value=value.replace(/[^\d^\.]+/g,'').replace('.','$#$').replace(/\./g,'').replace('$#$','.')"
> 僅允許輸入一個小數點。