I would like to have a regular expression that checks if a string contains only upper and lowercase letters, numbers, and underscores.
To check the entire string and not allow empty strings, try
^[A-Za-z0-9_]+$