Prevent the negative value in number fields even iphan (-) and character (e) in number input type

If we use number type in input field. In this case it will allows the characters are (e) and (-). Here we can restrict that character while we do input.


Solution:


Keycodes: e : 69, - : 189


<input type="number" onkeydown="return event.keyCode !== 69 && event.keyCode !== 189" />


Reference for keycode finder : 
https://keycode.info/

Demo:

https://stackblitz.com/edit/typescript-cwc9ge?file=index.ts

Comments

Popular posts from this blog

Your build is currently configured to use incompatible Java 21.0.3 and Gradle 8.2.1. Cannot sync the project.

Error in Android Migration Gradle 7.5 to 8.5 - java.lang.NullPointerException: Cannot invoke "String.length()" because "" is null

How to clean up the unused imports, variable and function from Typescript