SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <input type="text" class="input">
  2.  
  3.     <script>
  4.         let input = document.querySelector('input');
  5.  
  6.         input.addEventListener('keydown', e => {
  7.             let isDigit = false;
  8.             let backSpace = false;
  9.             let isDash = false;
  10.  
  11.             if (e.key >= 0 || e.key <= 9) {
  12.                 isDigit = true;
  13.             }
  14.  
  15.             if (e.key === 'Backspace' || e.key === '-') {
  16.                 backSpace = true;
  17.                 isDash = true;
  18.             }
  19.  
  20.             if (!isDigit && !backSpace && !isDash) {
  21.                 e.preventDefault();
  22.             }
  23.         });
  24.     </script>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top