JS
React JS
React - How To Allow Only Numbers In Textbox?
Today, i will let you know example of allow only numbers in textbox react js. This article will give you simple example of allow only numbers in input field react. i explained simply about only numbers allowed in textbox reactjs. This tutorial will give you simple example of react allow only numbers in input.
- TAGS
- React JS
- 4.5/5.0
- Last updated 08 September, 2022
- By Admin
In this example, i will show you simple example of allow only number in input text field in react js. we will write that code on change event. i take one number text field and you can only enter number in that textbox.
So, let see bellow example code for enter only number in textbox react js.
Example Code:
import React, { Component } from 'react'; import { render } from 'react-dom'; class App extends Component { constructor() { super(); this.state = { number: '' }; this.handleChange = this.handleChange.bind(this); this.handleSubmit = this.handleSubmit.bind(this); } handleChange(event) { const re = /^[0-9\b]+$/; if (event.target.value === '' || re.test(event.target.value)) { this.setState({number: event.target.value}) } } handleSubmit(event) { console.log(this.state); event.preventDefault(); } render() { return ( ); } } render(, document.getElementById('root'));How to Allow Only Numbers in Textbox in React - codewale.com
Now we are ready to run our application, so let's run using bellow command:
npm start
Open bellow url:
http://localhost:3000
I hope it can help you...
Categories
PHP
(5)
Codeigniter
(5)
Laravel
(3)
JS
(1)
Angular JS
(5)
Node JS
(5)
Vue JS
(4)
React JS
(6)
jQuery
(5)
Javascript
(3)
jQuery UI
(6)
Wordpress
(1)
Python
(5)
Database
(1)
MySql
(5)
Mongo DB
(1)
DBMS
(1)
SQL
(5)
HTML
(1)
HTML 5
(5)
CSS
(5)
Bootstrap
(5)
Ajax
(5)
JAVA
(1)
JSON
(5)
Ubuntu
(5)
Server
(5)
Git
(3)
Google
(1)
Google Map
(7)
Google API
(1)
Elastic Search
(1)
Apache
(1)
Installation
(1)