Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialkaran Badhwar
Web Development Techdegree Graduate 18,135 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}$/