I want users to create a username with some conditions.
The username must be 6 or more characters in length.
It can contain an underscore but it's not required.
It can contain a-z or A-Z or 0-9 characters.
currently, this is what I put for validation
var usern= /^[a-zA-Z0-9_]{6,}[a-zA-Z]+[0-9]*$/;
but the username is not working if it is joseph_123, joseph123_ or jose123
You can use the \w Metacharacter. Matches a-z, A-Z, 0-9, and the _ (underscore).
^\w{6,}$
const TESTS = ['joseph_123', 'joseph123_', 'jose123' ,'1234', 'á123456', '1223456á', 'abc-def']
TESTS.forEach((uname) => {
console.info(uname + ': ' + uname.match(/^\w{6,}$/))
})