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 :: add required attribute javascript 
Javascript :: how to assign value to variable 
Javascript :: jquery .click function call 
Javascript :: formik react native 
Javascript :: settimeout function javascript for loop 
Javascript :: remove repeated characters from a string in javascript 
Javascript :: offsetheight javascript 
Javascript :: discord.js emoji in embed 
Javascript :: how to find repeated characters in a string in javascript 
Javascript :: moment get timezone 
Javascript :: how to change background color though props 
Javascript :: open sans font react js 
Javascript :: array map destructuring 
Javascript :: jquery child selector 
Javascript :: angularjs date filter 
Javascript :: Add an element to an array at a specific index with JavaScript 
Javascript :: how to find for lable in jquery 
Javascript :: js how to work with float 2 decimal numbers 
Javascript :: update data firestore 
Javascript :: Round to at most 2 decimal places 
Javascript :: javascript merge array 
Javascript :: sequelize sqlite example 
Javascript :: react native location 
Javascript :: .net mvc javascript function call link 
Javascript :: how to save and use item from local storage javascript 
Javascript :: counter in javascript 
Javascript :: javascript convert array to object 
Javascript :: setting timeout in javascript 
Javascript :: javascript convert a number in string 
Javascript :: span change jquery 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =