I've been testing my code all day, but nothing happens. The form automatically opens the success.html and doesn't use the script.
function FormValidation(theForm) {
var errors = "";
var alph = /^[\w ]+$/;
var cardnumb = /^\d{16}$/;
var cvvnumb = /^\d{3}$/;
var monthnumb = /^\d{1,2}$/;
var yearnumb = /^\d{4}$/;
if (form.one.value == "") {
errors += "Please enter your full name! \n";
}
else if (!alph.test(form.one.value)) {
errors += "Full name is wrong or includes invalid characters! \n";
}
if (form.two.value == "") {
errors += "Please enter your 16-digit code! \n";
}
if (!cardnumb.test(form.two.value)) {
errors += "Card number does not consist of 16 digits or includes invalid characters! \n";
}
if (form.three.value == "") {
errors += "Please enter your month of expiration! \n";
}
if (!monthnumb.test(form.three.value)) {
errors += "The month does not consist of 2 digits or includes invalid characters! \n";
}
if (form.four.value == "") {
errors += "Please enter your year of expiration! \n";
}
if (!yearnumb.test(form.four.value)) {
errors += "The year does not consist of 4 digits or includes invalid characters! \n";
}
if (form.five.value == "") {
errors += "Please enter your 3-digit CVV code! \n";
}
if (!cvvnumb.test(form.five.value)) {
errors += "The CVV does not consist of 3 digits or includes invalid characters! \n";
}
if (!content == "") {
alert(content);
return false;
}
}
<!DOCTYPE html>
<html lang="en-US" class="Html" id="Main" dir="auto">
<head class="Head" id="Main">
<link rel="stylesheet" type="text/css" href="style.css">
<meta name="description" content="NRN">
<meta name="author" content="NRN">
<title class="Title" id="Title">NRN</title>
</head>
<body class="Body" id="Main">
<nav>
<ul>
<li><a href="index.html">Home</a></li>
</ul>
</nav>
<p class="p1">Payment form validation using JavaScript<p>
<form method="POST" action="success.html" class="myForm" name="myForm" onSubmit="javascript:return FormValidation(this)">
<div class="form-group-name">
<label for="name">Owner</label><br>
<input type="text" placeholder="Name on card" class="form-control-1" id="one" name="one">
</div>
<div class="form-group-number">
<label for="number">Card number</label><br>
<input type="text" placeholder="16-digit code" class="form-control-2" id="two" name="two">
</div>
<div class="form-group-date">
<label for="date">Expiration date</label><br>
<input type="text" placeholder="Month" class="form-control-3" id="three" name="three">
<input type="text" placeholder="Year" class="form-control-3" id="four" name="four">
</div>
<div class="form-group-cvv">
<label for="cvv">CVV</label><br>
<input type="text" placeholder="3-digit code" class="form-control-4" id="five" name="five">
</div>
<div class="form-group-submit">
<input type="submit" class="submit_form" value="Validate">
</div>
</form>
</body>
</html>
I have checked everything, as well as many tutorials too, but it doesn't help. Please help! Thanks in advance! Could the problem be in the .css file?