79405735

Date: 2025-02-01 21:55:14
Score: 2
Natty:
Report link

You can use preventDefault function of the onKeyDown event of input element if you know a character is not in english. How do you know it's not english? You can use my trick without using regular expressions: in such events, event variable is of type KeyboardEventHandler.
(event: KeyboardEvent<HTMLInputElement>) => { if(event.code.toLowerCase().includes(event.key.toLowerCase())) return null event.preventDefault() /* prevent event from typing the character in input field as it is not an english character*/ }
this block of code checks if the pressed key character ("s") is included within the key code ("keyS") which is in english just be careful to check the lowercase values as it may run into some exceptions without checking that.

Reasons:
  • Blacklisted phrase (1): How do you
  • Whitelisted phrase (-1.5): You can use
  • RegEx Blacklisted phrase (2.5): do you know it
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (0.5):
Posted by: Saleh Alikhani