sebuahhobi

regex min 9 max 9

Oct 30th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.97 KB | None | 0 0
  1. <script type="text/javascript">
  2.                         function validate(evt) {
  3.                           var theEvent = evt || window.event;
  4.  
  5.                           // Handle paste
  6.                           if (theEvent.type === 'paste') {
  7.                               key = event.clipboardData.getData('text/plain');
  8.                           } else {
  9.                           // Handle key press
  10.                               var key = theEvent.keyCode || theEvent.which;
  11.                               key = String.fromCharCode(key);
  12.                           }
  13.                           //var regex = /[0-9]|\./; ini hanya angka
  14.                           var regex = /[0-9]^\w{0,10}$|\./; //saya mau min. 9 max. 9
  15.                           if( !regex.test(key) ) {
  16.                             theEvent.returnValue = false;
  17.                             if(theEvent.preventDefault) theEvent.preventDefault();
  18.                           }
  19.                         }
  20. </script>
Add Comment
Please, Sign In to add comment