Created
August 8, 2020 15:01
-
-
Save framp/267667aaac7ff183f3f5548e8ebb06cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default (props) => ( | |
<input | |
onKeyDown={(event) => { | |
const { keyCode } = event; | |
if ( | |
(keyCode >= 8 && keyCode <= 9) || //BACKSPACE and TAB | |
(keyCode >= 37 && keyCode <= 40) || // Arrows | |
keyCode === 46 || //DEL | |
keyCode === 190 || //DEL | |
(keyCode >= 48 && keyCode <= 57) || // Numbers | |
(keyCode >= 96 && keyCode <= 105) // Numeric pad | |
) { | |
return; | |
} | |
event.preventDefault(); | |
}} | |
type="text" | |
inputmode="numeric" | |
pattern="[0-9.]*" | |
{...props} | |
/> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment