Advertisement
Virajsinh

onkeyup Validation jQuery

Feb 17th, 2022 (edited)
2,310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.29 KB | None | 0 0
  1. // https://jsfiddle.net/hibbard_eu/vY39r/
  2.  
  3. $("#amount").on("keyup", function(){
  4.     var valid = /^\d{0,2}(\.\d{0,2})?$/.test(this.value),
  5.         val = this.value;
  6.    
  7.     if(!valid){
  8.         console.log("Invalid input!");
  9.         this.value = val.substring(0, val.length - 1);
  10.     }
  11. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement