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 Username

karan karan
seal-mask
.a{fill-rule:evenodd;}techdegree
karan karan
Web Development Techdegree Student 12,698 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 🙂