How to check if a string only contains certain characters in js?

I'm making a discord bot that allows you to play hangman. I need to check if a string only contains lowercase english letters and hyphens ("-").

I know how to check if it contains or doesn't contain certain characters, but how do I check if it only contains specific characters?

Read more here:

Content Attribution

This content was originally published by 5akr1 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: