Simply way in React
<input
onKeyPress={(event) => {
if (!/[0-9]/.test(event.key)) {
event.preventDefault();
}
}}
/>
More Related Contents:
- Split a string between special characters [closed]
- “SyntaxError: Unexpected token < in JSON at position 0"
- ReactJS – Does render get called any time “setState” is called?
- Regex to match all instances not inside quotes
- React onClick function fires on render
- React – User-Defined JSX Components Not rendering
- Template literal inside of the RegEx
- How to access a child’s state in React
- Is there any way to update a specific index from the array in Firestore
- JavaScript regex pattern concatenate with variable
- Detecting when user scrolls to bottom of div with React js
- Executing async code on update of state with react-hooks
- How to change the value of a Context with useContext?
- How target DOM with react useRef in map
- Event target is null inside functional setState
- Regex for Umlaut
- Sort an array of objects in React and render them
- How can I update an object inside of an array in firestore? [duplicate]
- Converting latitude and longitude to decimal values
- Increase JavaScript Heap size in create-react-app project
- Global state in React Native
- Remove all occurrences except last?
- What is the best way to parse html in google apps script
- Conditional Validation in Yup
- react button onClick redirect page
- Could not find “store” in either the context or props of “Connect(App)”
- Class based component vs Functional components what is the difference ( Reactjs ) [duplicate]
- Why this regex is not working for german words?
- Preg_match to regex equivalent expression to match any Unicode letters
- value of using React.forwardRef vs custom ref prop