What's new
HTML Forums | An HTML and CSS Coding Community

Welcome to HTMLForums; home of web development discussion! Please sign in or register your free account to get involved. Once registered you will be able to connect with other members, send and receive private messages, reply to topics and create your very own. Our registration process is hassle-free and takes no time at all!

Validation does not work

Karl

New member
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?


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>
 
Hi ani,
thank you for your reply.

Do you mean here:

```
<script type="text/javascript">
function validateFirstName() {
var field = document.getElementByID("").value;
```

This also do not seem to work.
 
replace: document.getElementByID("").value;
to: document.getElementByID("").value;

I believe it is: getElementById("enterYourId")
 
The next step in software design https://mlsdev.com/blog/hire-a-development-team is auxiliary documentation. Aside from formal validation techniques, auxiliary documentation is essential for capturing the concepts and methods used to model problem space. As the process continues, it's vital to ensure that your designs are functional and will meet the specifications of your project. Whether you want a simple web application or a complex application that is a complex piece of software, you can be sure that this process will produce a product that's worth the investment.
 
Last edited:
I have been trying to get into learning how to code for a while now but I have been able to do it. Reading about this now have picked on my interest again. I'm going to checkout Udemy courses and see which one to join in coding .
 
Back
Top