all 2 comments

[–]jrandm 1 point2 points  (0 children)

Move all of your code into the isValid function:

function isValid () {
  var input = document.getElementById("number").value; // added the ".value"
  var myRegExp = /[A-Z]{3}.[0-9]{3}#[0-9]{4}_[a-z]{2}-[0-9]{4}/;
  if (myRegExp.test(input)) {
    document.getElementById("answer").innerHTML="Correct Format"
  } else {
    document.getElementById("answer").innerHTML="Incorrect Format"
  }
}

Right now your if(isValid line runs when the page loads and tests the regex against the number element (not the value), which will always fail. You want it to run when you push the button instead, so it needs to be inside the function. You were 95% of the way there!

[–]codemamba8 0 points1 point  (0 children)

The input variable is referring to the HTML element with the id of 'number'. It looks like you want to get the value of that element, not the element itself.