This regex pattern matches a valid username that consists of alphanumeric characters (both uppercase and lowercase), underscores, with a length between 5 and 20 characters.
const regex = /^[a-zA-Z0-9_]{5,20}$/; 
const username = 'john_doe123'; 
if (regex.test(username)) { 
    console.log('Valid username'); 
} else { 
    console.log('Invalid username'); 
}Kopieren