EasyRegex Logo
EasyRegex
New

Validate Username with Uppercase, Lowercase, and Number in Any Order

Javascript

Regular Expression

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{3,}$
Copy
Do you have Feedback?

Explanation

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.

Javascript

Example Usage

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
Test the expression

Similar Regular Expressions