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.

karan karan
Web Development Techdegree Student 12,697 PointsDefine 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
^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$
can somebody explain this,
1 Answer

Brian Jensen
Treehouse StaffHiya karan karan
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:
/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$/
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:
/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,20}$/