vue input只能輸入兩位小數的,不能是負數

2021-09-26 08:02:12 字數 669 閱讀 9593

input 設定為text,number型別能輸入負值和 『e』

export const getnumber = (val,oldval, l) => )?$/

let mum = val

let nmb = l + 1

if (!reg2.test(val))

if (val[0] === '0' && val[1] !== '.' && val.tostring().length > 1)

if (val[0] === '0' && val[1] === '0' && val.tostring().length > 1)

let i = val.tostring().indexof('.')

if (val.tostring().indexof('.') > 0 && val.tostring().length > (val.tostring().indexof('.') + 2))

if (isnan(val))

if (val === '' || val == null)

return mum

}

這種小數點後面沒數字的 需要在失去焦點的時候提示使用者,或者給input繫結乙個失去焦點觸發的方法,如果失去焦點最後乙個是小數點的話就去掉小數點

遇見問題,留作參考

只能輸入數字且只能兩位小數的input框驗證

只能輸入數字且只能兩位小數 vue.prototype.check decimal function decimal g,只保留第乙個.清除多餘的 replace replace g,replace replace d d d 1 2.3 只能輸入兩個小數 replace 0 9 i,以上已經過濾,...

vue input框數字後保留兩位小數正則

type text v model.trim ruleform2.marketprice maxlength 10 keyup.native ruleform2.marketprice ruleform2.marketprice ruleform2.marketprice.replace d.g,r...

input驗證只能輸入乙個保留兩位小數的數字

在input驗證的時候,由於一些相容性的問題,很少會使用h5自帶的 input type number 和 pattern屬性。這邊有兩個現成的方法,來驗證input 只能輸入整數和可以輸入小數,但保留兩位小數的方法。驗證input只能輸入乙個小數點,s首個字元不能為點 param val inpu...