This regex pattern uses positive lookaheads to ensure that the string contains at least one lowercase letter, one uppercase letter, and one digit. The order of these characters in the string does not matter. The pattern also enforces a minimum length of 3 characters.
const usernameRegex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{3,}$/;
const username = 'Us3rname123';
if(usernameRegex.test(username)) {
console.log('Valid username');
} else {
console.log('Invalid username');
}
Copy