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

Joseph Escobedo
seal-mask
.a{fill-rule:evenodd;}techdegree
Joseph Escobedo
Full Stack JavaScript Techdegree Student 4,172 Points

Regex challenge.

I cant tell why it wont let me pass, Its asking me to limit the regex, but i dont really see how.

heres what I have.

// Type inside this function
function isValidHex(text) {
  const hexRegEx = /#([a-f0-9]){6}/i
}

And this is what I get as a failed response.

Your regular expression matches CSS hexadecimal color values, but also matches other values. See if you can limit your regex to meet the requirements.

link to challenge: https://teamtreehouse.com/library/regular-expressions-in-javascript/validating-a-form/form-validation

1 Answer

Megan Carson
Megan Carson
2,350 Points

Here is a regex that will help you pass the challenge:

function isValidHex(text) {
  const hexRegEx = /^#([a-f0-9]){6}$/i
}

The '^' checks for the beginning of the string, meaning make sure the '#' is at the beginning of the string.

The '$' checks for the end of the string, meaning make sure that after 6 hexadecimal values the end of the string comes.