Skip to main content

Posts

Showing posts with the label Number

Allow only numbers in Input in React | Regex and Number

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 );  ...