Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react allow only numbers in input

class App extends React.Component{
   constructor(){
      super();
      this.state = {value: ''};
      this.onChange = this.onChange.bind(this)
   }
   
   onChange(e){
      const re = /^[0-9]+$/;
      if (e.target.value === '' || re.test(e.target.value)) {
         this.setState({value: e.target.value})
      }
   }
   
   render(){
     return <input value={this.state.value} onChange={this.onChange}/>
   }
}

ReactDOM.render(<App/>,document.getElementById('app'))
Comment

PREVIOUS NEXT
Code Example
Javascript :: discord.js custom create channel 
Javascript :: node js favicon.ico 
Javascript :: express js get origin 
Javascript :: preview image file upload javascript 
Javascript :: get query param javascript 
Javascript :: onclick prevent default 
Javascript :: set delay react native 
Javascript :: how to call await outside async function in js 
Javascript :: create-react native app without expo 
Javascript :: add event listener on modal close 
Javascript :: how to set form control value in angular 
Javascript :: mongoose connection nodejs 
Javascript :: js dom get website name 
Javascript :: generate random base 64 string js 
Javascript :: how to find angle between two points 
Javascript :: node string to json 
Javascript :: react native textinput turnoff capitalize first letter 
Javascript :: javascript detect collision 
Javascript :: javascript group by property array of objects 
Javascript :: mongoose connect database name 
Javascript :: javascript regex number only 
Javascript :: javascript object toarray 
Javascript :: write html is jsx extension for vscode 
Javascript :: adding integers jquery 
Javascript :: javascript to mask email address 
Javascript :: nodejs 16 install 
Javascript :: insta icon in next js 
Javascript :: detect fullscreen mode 
Javascript :: avaScript slice() With Negative index 
Javascript :: conditinally add object js 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =