Every time user enter, value is checked with regular expression, I'm trying to restrict user from entering further into input field if regexp is not matched 

Using keyup event, preventdefault never fires and using keypress event, user is unable to input at all because in the begining, value in input field shows as "" (nothing) 

[![on keyup val="2"](https://i.stack.imgur.com/xXYD1.png)](https://i.stack.imgur.com/xXYD1.png)

[![on keypress val="1"](https://i.stack.imgur.com/W1gUd.png)](https://i.stack.imgur.com/W1gUd.png)

```
var discountRegex = /(^100([.]0{1,2})?)$|(^\d{1,2}([.]\d{1,2})?)$/
            $("#" + (idOfElement)).on("keyup",function (e) {

                var val=this.value
                var k = e.keyCode
                if(k==46 ||(k > 48 && k <97)){
                    console.log(k)
                    return discountRegex.test(val);
                }

            });

```

in the above code idOfElement is the id i get on whichever field i focus.