Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Regular Expressions in JavaScript Validating a Form Validating a Password

karan karan
karan karan
Web Development Techdegree Student 12,697 Points

Define length for password

How to define length for password, That this should be at least the length of the password? I tried looking up online for this, but did not get it


can somebody explain this,

1 Answer

Brian Jensen
.a{fill-rule:evenodd;}techdegree seal-36
Brian Jensen
Treehouse Staff

Hiya karan karan :wave:

This RegEx that you added to your post, is checking if there is at least one of each of a lowercase letter, uppercase letter and a number:


If you wanted to also add a minimum and maximum password length, you can use a Quantifier. For example if you wanted the password to have a minimum length of 8 characters and a maximum of 20, as well as still ensuring that there is at least one of each of a lowercase letter, uppercase letter and a number, you would change the RegEx to this: