Advertisement
kura2yamato

perbaikan 004

Oct 1st, 2021
1,428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.62 KB | None | 0 0
  1. <head>
  2.     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  3. </head>
  4. <body>
  5. <form name="atur_harga" action="" method="POST">
  6.  <label for="desimal">Input Desimal :</label>
  7.  <input type="text" class="harga" id="desimal" value="">
  8. </form>
  9.  
  10. <script type="text/javascript">
  11. $(document).click(function() {
  12.  
  13.   $(".harga").on("keyup", function() {
  14.     var valid = /^\d{0,15}(\.\d{0,2})?$/.test(this.value),
  15.       val = this.value;
  16.  
  17.     if (!valid) {
  18.       console.log("Invalid input!");
  19.       this.value = val.substring(0, val.length - 1);
  20.     }
  21.   });
  22.  
  23. });
  24.  
  25. </script>
  26.  
  27. </body>
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement