I am currently working on a project that involves an HTML file and an external JavaScript file. In the HTML file, there is user input and a validation button that triggers the courseValidation() function when clicked. However, I am facing an issue with the if statement in the JavaScript code. Even when the input does not match myRegExp, it always displays "Correct Format" on the page instead of "Incorrect Format". I'm still learning and would appreciate any guidance or suggestions to help me troubleshoot this issue.
Here is the structure of the files:
<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");
}
}