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 trial

JavaScript Regular Expressions in JavaScript Validating a Form Validating a Username

karan Badhwar
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
karan Badhwar
Web Development Techdegree Graduate 18,135 Points

^[a-z]+$

Why is this working, if I put abcDefg, the tool tip is still there, but as per the code I understood, while writing abcD 'D' was once at the end, but then we overwrite it with efg why the tool tip is still there?

1 Answer

Rohald van Merode
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree seal-36
Rohald van Merode
Treehouse Staff

Hi karan karan,

That happens because of the $ at the end of your RegEx. This indicates that the string has to finish with the part in front of it. Which is in this case is lowercased letters. Since you're using both the ^ and $ here and there's nothing else in between other than the lowercased letters it will only pass when the string both starts and ends with lowercased letters.

Hope this helps 🙂