I would like to have a regular expression that checks if a string contains only upper and lowercase letters, numbers, and underscores.
There's a lot of verbosity in here, and I'm deeply against it, so, my conclusive answer would be:
/^\w+$/
\w is equivalent to [A-Za-z0-9_], which is pretty much what you want. (unless we introduce unicode to the mix)
Using the + quantifier you'll match one or more characters. If you want to accept an empty string too, use * instead.