(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')
这个只能限制小数两位数 综合限制整数不超过五位数怎么写 (?_?)
<Form.Item style={{ margin: 0 }}>
{form.getFieldDecorator(dataIndex, {
initialValue: record[dataIndex],
getValueFromEvent: (event) => {
return event.target.value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1') // 这里应该怎么改?
},
})(
<Input style={{width:"100px"}} initialvalue={this.state.inputValueDefault} ref={node => (this.input = node)} onPressEnter={this.save} onBlur={this.save} />)
}
</Form.Item>
这是一个可编辑单元格 整数部分限制输入几位数,小数部分限制输入几位小数这种方法
###这样应该就可以了
/^\d{1,5}(\.\d{1,2}){0,1}$/
###function testNumber(num) {
return /^\d{1,5}(?:\.\d{1,2})?$/.test(num.toString())
}
[1, 1.2, 1.23, 1.234, 12, 123, 1234, 12345, 123456, 12.3, 12.34, 12.345, 12345.67].reduce((res,n) => (res[n] = testNumber(n), res), {})
###let reg = /^\d{1,5}(\.\d{1,2})?$/
###Input限制了只能输入数字吗,如果是只输入数字是不是可以考虑用inputNumber,有现成的api限制小数位数呢
###<Form.Item style={{ margin: 0 }}>
{form.getFieldDecorator(dataIndex, {
initialValue: record[dataIndex],
getValueFromEvent: (event) => {
return event.target.value.replace(/^\D*(\d{0,5}(?:\.\d{0,2})?).*$/g, '$1') // 重点!!!限制小数点前5位数,小数点后2位数
},
})(<Input style={{width:"100px"}} initialvalue={this.state.inputValueDefault} ref={node => (this.input = node)} onPressEnter={this.save} onBlur={this.save} />)
}
</Form.Item>
目前只有这样
注意: 会出现 输入框里原本的值含小数的时候(比如: 7.45), 修改小数点前面的值 一直输 输到满第5位了(比如: 11117.45), 再输入(也就是点第七下的时候)小数点后面的值会被挤掉会消失(比如: 11117 ), 不知道怎么回事 不知道还有没有别的更好的方法