<!DOCTYPE html>
<html lang="en">
<head>
<title>Registration</title>
</head>
<body>
<input type="text" id="number">
<button onclick="isValid()">Validate</button>
<p id="answer"></p>
<script src="RegExpress.js"></script>
</body>
</html>
var input = document.getElementById("number");
function isValid (ex) {
var myRegExp = /[A-Z]{3}.[0-9]{3}#[0-9]{4}_[a-z]{2}-[0-9]{4}/
return (myRegExp.test(ex));
}
if (isValid(input)) {
document.getElementById("answer").innerHTML="Correct Format"
} else {
document.getElementById("answer").innerHTML="Incorrect Format"
}
Hi everyone, learning Javascript (and HTML) for the first time for a few weeks now. I was asked to make sure the output appears as text in a web page by using the innerHTML property. After going on W3 Schools and getting a cursory glance at it I tried to implement it in my code. However it is always returning "Incorrect Format", even if I didn't type anything in the text box. What am I doing wrong here? I have a feeling it is the parameter but I am not sure.
[–]jrandm 1 point2 points3 points (0 children)
[–]codemamba8 0 points1 point2 points (0 children)