How would I go about checking if a keycode is valid?

I’m working on a gui with a setting to allow players to set a key to open and close it. Whenever an invalid code is inputted it breaks the script. I thought that I could just make a table with a list of all valid keys, but I would like to know if there is a better way to do it before I resort to that method.

Thank you in advance.

Have you used if statements checking for the input KeyCode?

if input.KeyCode == Enum.KeyCode.E then
    print("Player pressed the E key!")

Wouldn’t I still have to have a whitelist of keys a player can choose from?