Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

input type number maxlength in react

import {useState} from 'react';

const App = () => {
  const [num, setNum] = useState('');

  const handleNumChange = event => {
    const limit = 4;
    setNum(event.target.value.slice(0, limit));
  };

  console.log(num);

  return (
    <div>
      <h2>123456789</h2>
      <input
        type="number"
        id="num"
        name="num"
        value={num}
        onChange={handleNumChange}
      />
    </div>
  );
};

export default App;
Comment

how to set max length of input in react js

for maxLength to work, type has to be 'text'
(most people are probably putting number)
Comment

PREVIOUS NEXT
Code Example
Javascript :: Plumasil - new item button text 
Javascript :: How to display html link inside table cell using reactjs material-table 
Javascript :: draw image inside canvas width 100% 
Javascript :: if the params of usequery updated 
Javascript :: return the remainder from two numbers javascript 
Javascript :: autonumeric stimulus 
Javascript :: create index with multiple fields mongo 
Javascript :: js point in rect 
Javascript :: javascript Change color based on a keys value in each object of array 
Javascript :: javascript Vue Component Loading Before Vuex Data Is Set 
Javascript :: google chrome extension v3 react content security policy issue 
Javascript :: Make a card dynamic with Angular JS 
Javascript :: angularjs Manipulate an element that is conditionally rendered 
Javascript :: angularjs How to populate ng-style with object of CSS 
Javascript :: Presenting backend data using AngularJS/AJAX in MVC VIEW 
Javascript :: Why is <CalendarStrip / not working properly 
Javascript :: .push( ) is not updating the variable 
Javascript :: python regex consecutive characters 
Javascript :: sending api with limited fields in express 
Javascript :: yaml request body json 
Javascript :: Another Example In JavaScript Event Delegation 
Javascript :: dfs javascript 
Javascript :: create a group or pool in phaser 
Javascript :: Creating New Transaction Object for blockchain 
Javascript :: A Nodule Module For ExpressJS 
Javascript :: cannot setState in event handler 
Javascript :: detect sound chrome extension every 1 second 
Javascript :: JavaScript get div height dynamically without jQuery 
Javascript :: how to check bot channel permissions 
Javascript :: var logEvenNums = function(num) {}; 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =