InRegex Logo
InRegex

Match Valid Username in Javascript

Explication

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.

Javascript

Expression Régulière

^[a-zA-Z0-9_]{5,20}$
Copier
Avez-vous des Retours ?
Javascript

Exemple d'Utilisation

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'); 
}
Copier

Testez l'expression

Expressions Régulières Similaires