Use value and onChange property of input field to allow only numbers in text-box. Inside the onChange handle check whether the entered value is valid number or not. Update the state only when entered value is a valid number. See the below example to do this. Example 1, You can use Number and conditionally change state. import React , { Component } from 'react' ; class AllowOnlyNumber extends Component { constructor ( props ) { super ( props ); this . state = { telephone: '' }; this . onHandleTelephoneChange = this . onHandleTelephoneChange . bind ( this ); ...
Angular, React, JavaScript, Java, PHP, SQL, C#, Vue, NodeJs, TypeScript and Interview Questions Answers