Skip to content

Instantly share code, notes, and snippets.

@aderbas
Created January 7, 2021 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aderbas/63ac49f6f1ad40a0b1e754dd964a85da to your computer and use it in GitHub Desktop.
Save aderbas/63ac49f6f1ad40a0b1e754dd964a85da to your computer and use it in GitHub Desktop.
/**
* only number field filter
*/
const keyRange = [...Array(11).keys()].map(x => x + 48);
export const onlyNumber = (e) => {
if(-1 === keyRange.indexOf(e.which)){
e.preventDefault();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment