Advertisement
krot

vue isNumber

Jan 25th, 2020
605
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <input type="text" v-on:keypress="isNumber"/>
  2. methods: {
  3.      isNumber:function($event){
  4.         let keyCode = ($event.keyCode ? $event.keyCode : $event.which);
  5.         if ((keyCode < 48 || keyCode > 57) && keyCode !== 46) { // 46 is dot
  6.             $event.preventDefault();
  7.         }
  8.      }
  9.  
  10.   },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement