diff --git a/src/number-picker/number-picker.jsx b/src/number-picker/number-picker.jsx index c33491fd48..e53eff2e8d 100644 --- a/src/number-picker/number-picker.jsx +++ b/src/number-picker/number-picker.jsx @@ -320,6 +320,9 @@ class NumberPicker extends React.Component { onChange(value, e) { // ignore space & Compatible Chinese Input Method value = value.replace('。', '.').trim(); + // 过滤非数字 + value = value.replace(/[^-.\d]/g, ''); + let onlyDisplay = false; if (this.props.editable === true && this.shouldFireOnChange(value)) { let valueCorrected = this.correctValue(value); diff --git a/test/number-picker/index-spec.js b/test/number-picker/index-spec.js index 466f2f19c2..ea9c7c4de2 100644 --- a/test/number-picker/index-spec.js +++ b/test/number-picker/index-spec.js @@ -127,7 +127,7 @@ describe('number-picker', () => { wrapper .find('input') .simulate('change', { target: { value: `${Number.MAX_SAFE_INTEGER}a2333` } }); - assert(wrapper.find('input').prop('value') === `${Number.MAX_SAFE_INTEGER}a2333`); + assert(wrapper.find('input').prop('value') === `${Number.MAX_SAFE_INTEGER}2333`); wrapper.find('input').simulate('blur'); assert(wrapper.find('input').prop('value') === `${Number.MAX_SAFE_INTEGER}2333`); wrapper @@ -148,7 +148,7 @@ describe('number-picker', () => { wrapper2 .find('input') .simulate('change', { target: { value: `${Number.MAX_SAFE_INTEGER}a2333` } }); - assert(wrapper2.find('input').prop('value') === `${Number.MAX_SAFE_INTEGER}a2333`); + assert(wrapper2.find('input').prop('value') === `${Number.MAX_SAFE_INTEGER}2333`); wrapper2.find('input').simulate('blur'); assert(wrapper2.find('input').prop('value') === `${Number.MAX_SAFE_INTEGER}2333`); wrapper2 @@ -322,6 +322,18 @@ describe('number-picker', () => { done(); }); + it('should only input -.1234567890', () => { + let wrapper = mount( + + ); + wrapper.find('input').simulate('change', { target: { value: '-1.' } }); + assert(wrapper.find('input').prop('value') === "-1."); + wrapper.find('input').simulate('change', { target: { value: '-1.a' } }); + assert(wrapper.find('input').prop('value') === "-1."); + wrapper.find('input').simulate('change', { target: { value: '-1.13a2' } }); + assert(wrapper.find('input').prop('value') === "-1.132"); + }) + it('onChange value 1.9 -> 1. should input displayValue === 1. onchange value === 1', done => { const onChange = (value) => { assert(value === 1)