Learn Regular Expressions by Building a Spam Filter - Step 15

Tell us what’s happening:

const dollarRegex = /[0-9]\sdollars/i; why is it still telling me that “Your character class should be 0-9”. what am i doing wrong here?

Your code so far

/* file: script.js */
const messageInput = document.getElementById("message-input");
const result = document.getElementById("result");
const checkMessageButton = document.getElementById("check-message-btn");

const helpRegex = /please help|assist me/i;

// User Editable Region

const dollarRegex = /[0-9]\sdollars/i;

// User Editable Region


const denyList = [helpRegex, dollarRegex];

const isSpam = (msg) => denyList.some((regex) => regex.test(msg));

checkMessageButton.addEventListener("click", () => {
  if (messageInput.value === "") {
    alert("Please enter a message.");
    return;
  }

  result.textContent = isSpam(messageInput.value)
    ? "Oh no! This looks like a spam message."
    : "This message does not seem to contain any spam.";
  messageInput.value = "";
});

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36

Challenge Information:

Learn Regular Expressions by Building a Spam Filter - Step 15

The \s character class doesn’t match only one space.
It matches any whitespace character including tab, new line and others.

If you want to match only a space character, you should use a literal space instead.

See: W3Schools

Screenshot 2025-06-10 125940

space part is not the issue i guess, because it only shows 1 error.

NeverMind I got it. Thanks for the help

1 Like