I would like to have a regular expression that checks if a string contains only upper and lowercase letters, numbers, and underscores.
use lookaheads to do the "at least one" stuff. Trust me it's much easier.
Here's an example that would require 1-10 characters, containing at least one digit and one letter:
^(?=.*\d)(?=.*[A-Za-z])[A-Za-z0-9]{1,10}$
NOTE: could have used \w but then ECMA/Unicode considerations come into play increasing the character coverage of the \w "word character".