Hi,
I'm a beginner in coding. I'm currently taking a course at Percipio and I've been struggling with a problem all day.
In my form the name should now be checked by using Javascript. More precisely, in my example, whether between 2 and 15 characters have been entered in the field firstname.
I've now made everything out except for the fields in question so that it is easier to see. In my opinion, I am compliant with the content of the training video. I didn't find a typo either, everything should be consistent as far as the names of the fields etc. are concerned.
I do not have a validation process or at least I cannot see the output of it. Can please someone give me a hint?
I'm a beginner in coding. I'm currently taking a course at Percipio and I've been struggling with a problem all day.
In my form the name should now be checked by using Javascript. More precisely, in my example, whether between 2 and 15 characters have been entered in the field firstname.
I've now made everything out except for the fields in question so that it is easier to see. In my opinion, I am compliant with the content of the training video. I didn't find a typo either, everything should be consistent as far as the names of the fields etc. are concerned.
I do not have a validation process or at least I cannot see the output of it. Can please someone give me a hint?
HTML:
<!DOCTYPE html>
<html>
<head>
<title>My first HTML form</title>
<script type="text/javascript">
function validateFirstName() {
var field = document.getElementByID("firstName").value;
var regex = /^[a-zA-Z]{2,15}$/;
if (regex.test(field))
document.getElementByID("message").innerHTML = "Input accepted";
else
document.getElementByID("message").innerHTML = "Please enter between 2 and 15 letters";
}
</script>
</head>
<body>
<H1>Your perfect vacation trip</H1>
<form>
Please enter your first name:<br>
<input id="firstName" type="text" onblur="validateFirstName();"/><span id="message"></span><br><br>
</body>
</html>