-1

Sorry, this question is maybe duplicated and answered here, but do not solve my problem.

I want to allow only numbers in my input outside return and in the nonstate component and inside props.

My code.js

const General = props => (
    <Row>
        <Col>
            <Form.Item>
                <Input />
            </Form.Item>
        </Col>
    </Row>
)

export default General
  • 1
    How is this question different from the one you linked? – Tobias S. Apr 26 '22 at 12:36
  • Setting it as `type="number"` should already limit the option to input anything else. You also have the `pattern` attribute which accepts a regex in the form of a string and tests that pattern on submission. You can also DIY this in a dedicated `onChange` function. – tomleb Apr 26 '22 at 12:39
  • @TobiasS. question is the same but does not have my answer. I want to implement that in props. – Sahil Hansda Apr 26 '22 at 12:40
  • thanks @tomleb it worked can we also limit input characters like max 10 – Sahil Hansda Apr 26 '22 at 12:43
  • Yes, https://www.w3schools.com/tags/att_input_maxlength.asp – tomleb Apr 26 '22 at 12:45

1 Answers1

-1

try this please.

State is here.

  const [obj, setobj] = useState({ number: 0 });

onChange function is here.

  const onChangeData = (event, type, value) => {
    let data = null;
    data = value;
    setobj({ ...obj, [type]: data })
  }

Pure input is here.

<input 
   type="number" 
   value={obj.number}  
   onChange={(event) => props.onChangeData("number",event.target.value)} />