I have an HTML file and an external JavaScript file. I have input from the user in the HTML and on the click on the validate button, the courseValidation() function is called. The problem is with the if statement. When the input does not match myRegExp, it should write that the format is incorrect to the page, but it always writes Correct Format, regardless if it is correct or not. Not sure what I am doing wrong. I'm just learning so no negative comments please.
HTML File:
<html lang="en">
<head>
<title>Validation</title>
</head>
<body>
<script src="course.js"></script>
<p>Enter Course Information:</p>
<input id="courseCode" type="text">
<button onclick="courseValidation()">Validate</button>
<p id="course"></p>
</body>
</html>
External JavaScript File:
function courseValidation() {
var courseCode = document.getElementById("course").innerHTML;
var myRegExp = /\D{3}.\d{3}#\d{4}_\D{2}-\d{4}/;
if (courseCode.match(myRegExp)) {
document.write("Incorrect Format");
} else {
document.write("Correct Format");
}
}