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

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.