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 an Email

Confused about /^[^@]+@[^@.]+\.[a-z]+$/i.test(email);

What does [^@] mean? Does it mean "any character" in JavaScript? Also, a simpler way to do this would be ^.*@.*\.[a-z]+$

1 Answer

Steven Parker
Steven Parker
231,275 Points

In a regular expression, "[^@]" is what's known as a "character class" and it means "any character other than an @ (at-sign)".

The brackets indicate a character class (code that will represent a single character), and when the first thing in it is a caret (^), it means "anything but" whatever follows. The @ has no special meaning and just represents itself.

So you don't want to replace it with the dot wildcard, because that would also match @.