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 Form Validation

Timothy Haryadi
seal-mask
.a{fill-rule:evenodd;}techdegree
Timothy Haryadi
Full Stack JavaScript Techdegree Student 6,323 Points

Stuck on "Regular Expression in Javascript": "The hexRegEx variable does not hold a regular expression object."

Hello, I'm currently on "Regular Expression in Javascript" and I'm stuck in a challenge task. I believe I got the regular expression correct but it's not accepting my code. Can some one take a look?

I've tried:

const hexRegEx = new RegExp(/^[#][a-z0-9]{6}$/gmi).test(text);

It works in the preview though.

Thanks!

1 Answer

Travis Alstrand
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Travis Alstrand
Data Analysis Techdegree Graduate 45,998 Points

Hey there Timothy Haryadi ! :wave:

You're very close! This is what got to pass for me

const hexRegEx = /^#[a-f0-9]{6}$/i;

It wasn't until I removed the new RegEx() code from the value I saw the error message change as it's just wanting the expression.

A very thorough explanation of this can be found here, I definitely recommend checking that out! :smiley:

Timothy Haryadi
seal-mask
.a{fill-rule:evenodd;}techdegree
Timothy Haryadi
Full Stack JavaScript Techdegree Student 6,323 Points

That did it! Thanks Travis, it also turns out that I had .test(text) at the end. I was ahead of myself. The test() part was supposed to be on the next step.