I have an input field where i am trying to block the special characters [dot, hiphen, space comma and e] so that user can't enter this special characters on both mobile and chrome.
function App() {
const handleInput = (event) => {
event.target.value = event.target.value.replace(/[e\.\- ]/g, "");
};
return ( <
div className = "App" >
<
input type = "number"
onInput = {
handleInput
}
/> < /
div >
);
}
// Render it
ReactDOM.render( <
App / > ,
document.getElementById("react")
);
<div id="react"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
Facing two issues on this, one is (999.) I am able to enter dot in between numbers, also when I enter some numbers and type hiphen then its clearing all the numbers (999-) => ().
How can I stop this two behaviour so that user can enter only 0-9 digits