不能输入:负号(-)零开头(0)
    正则算法

    1. formatter = (value) => (`${value.toString().replace(/^(0+)|[^\d]+/g, '')}`)
    2. parser = (value) => (`${value.toString().replace(/^(0+)|[^\d]+/g, '')}`)

    使用

    1. formatter={this.formatter}
    2. parser={this.parser}

    例:

    1. 'use strict'
    2. import React from 'react'
    3. import {
    4. InputNumber
    5. } from 'antd'
    6. import styles from '../../../../../../assets/Products.scss'
    7. /**
    8. * edit product SupplierReceiveGoodsDays (供应商到货天数)
    9. */
    10. export default class ProductEditSupplierReceiveGoodsDays extends React.Component {
    11. //不能为负数
    12. formatter = (value) => (`${value.toString().replace(/^(0+)|[^\d]+/g, '')}`)
    13. parser = (value) => (`${value.toString().replace(/^(0+)|[^\d]+/g, '')}`)
    14. variationsChangeChildren = (value) => {
    15. this.props.variationsChangeChildren(value, this.props.record, 'GoodsDays')
    16. }
    17. render () {
    18. const { max, value, disabled } = this.props
    19. return (
    20. <div className={styles['input-group-content']}>
    21. <span className={styles['input-group-addon']}>天</span>
    22. <InputNumber
    23. value={value}
    24. min={0}
    25. max={max}
    26. disabled={disabled}
    27. className={styles['input-number']}
    28. style={{ width: '140px' }}
    29. formatter={this.formatter}
    30. parser={this.parser}
    31. onChange={this.variationsChangeChildren}
    32. />
    33. </div>
    34. )
    35. }
    36. }