How to prevent “+”, “-“, “e”, “E” character in input “type=number”
When we use <input type="number">
in HTML form, it can accept some special characters also like +
, -
, e
, E
etc. If you don’t need those characters, a small Javascript can help prevent it from happening.
$( "input[ type=number ]" ).on( "keydown", function( e ){
if ( [ "+", "-", "e", "E" ].includes( e.key ) ){
e.preventDefault( );
}
} );