score:4
const handleChange = (e) => {
const value = e.target.value;
const clean = value.replace(/,/g, "");
const regex = /^[0-9]*\.?[0-9]*$/;
if (value && clean.match(regex)) {
if (!value.includes(".")) {
const formatted = new Intl.NumberFormat().format(parseFloat(clean));
setDisplayVal(formatted);
} else {
setDisplayVal(value);
}
} else {
setDisplayVal("");
}
};
<input
className="cal__section__form__container--input"
placeholder={0}
type="text"
value={displayVal}
onChange={handleChange}
/>
Source: stackoverflow.com
Related Query
- How to input decimal numbers and auto format with thousand separators at the same time in javascript?
- How to get label values dynamically and adding the numbers together from different input with reactjs
- How to fill input with button's innerText and also entered from the keyboard at the same time in React?
- How to prevent auto input value change with same name and same onchange function in reactJs?
- How to limit the text filed length with input type number in React JS and prevent entry of E,e, -, + etc
- How to set defaultValue, value={this.props.value}, and update the value of a text input with React?
- Make cards and images the same size - how can I do it with CSS?
- React Router V4: How to render a modal in the same screen changing only the url and then with that url, be able to rebuild the whole screen
- how to run my node application and react app in the same time with one command?
- How do I change the order of the Gradient in Format Column with AG Grid and AdapTable
- How to distinguish between a prop and a method with the same name, in Vue?
- Sort a json with nested objects structure and return a format same as the structure of json
- How do I use the error prop and css for Input API of Material UI with context
- React Router v6 : How to render multiple component inside and outside a div with the same path
- I have a data inside the state in T and Z format and React input accepts in the HH:MM ss format so how to convert
- How to group arrays of objects by value and add the result to another array with same value at specific key
- How to fix 'flattenChildren(...): Encountered two children with the same key' with React and Semantic UI
- How can I set the state and return JSX with the same function
- Place label and input field on the same row, with padding
- How to fetch data and make a route with the same endpoint React
- How can I shuffle an array of objects on page render and map over the shuffled array without console warning of "two children with the same key"?
- How can render the same card with different values based on user input in a form?
- How to have the same date format in mongo and react?
- How to limit number with 0-999 and just three numbers after the comma in React
- How do I update URL parameters and call fetch while on the same page with React?
- How do I format AntD form input fields such as phone numbers and SSNs in React?
- React useState: How can I update my useState with onChange for input and OnClick for the button?
- How can I handle change in multiple input field and send the data to an api with axios?
- How to let the user input number and increase it with a button in React JS
- How do I resolve eslint conflict between props and module imports with the same name?
More Query from same tag
- My material UI custom classes are being overridden by material UI's default classes
- How can I disable chunk(code splitting) with webpack4?
- Javascript Array Map by Object Attributes
- React native JAVA_HOME is set to an invalid directory
- React change font text color of all children inside div
- React/Typescript error when adding promise to a function?
- make document.execCommand('insertText', false, 'message') work with draftjs?
- Can i use multiple state value inside conditional rendering - ReactJs
- Private Route getting called dozens of times in React
- How to Require React Components In Console
- Reference SCSS Variable Internally Within Component
- React functional component does not handle event
- how to add key value of same index with another key value of same index in react
- How to loop a component when I click a h3 tag in react using Hooks
- How to reset child elements' state?
- Cannot read property 'toObject' of undefined when trying to call a func property
- Cannot read propery "comments" of undefined
- Dynamically Delete Elements
- React router - dynamic routes - accessing state object via the router
- How to return a function within a function and display it in return
- Error: Objects are not valid as a React child (found: object with keys {}). If you meant to render a collection of children, use an array instead. JS
- Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- Loop values in Typescript
- props.onChange(e.target.value) returns an object instead of a value in textField in material ui
- Is there any way to detect individual elements rendering in React Component properly? (Not Components rendering)
- Can a react/javascript object child have a value and children at the same time?
- How to display custom <Errormessage> in formik field component and disable the default message
- How to save axios GET response data as json or as same as the arrived response
- Jest mock with TypeScript
- styled-components doesn't update Navlinks attributes properly