Validation of forms JavaScript

<!DOCTYPE html>
<html lang="en">

 <meta charset="UTF-8">
 <link rel="stylesheet" href="">
 <link rel="stylesheet" href="" integrity="sha384-nn4HPE8lTHyVtfCBi5yW9d20FjT8BJwUXyWZT9InLYax14RDjBj46LmSztkmNP9w" crossorigin="anonymous">
 <!--[if lte IE 8]>
 <link rel="stylesheet" href="">
 <!--[if gt IE 8]><!-->
 <link rel="stylesheet" href="">
 <link rel="stylesheet" href="style/form.css">


 <div class="content">
 <p>Please fill in the contract form and send it for booking..</p>
 <form id="registration_form" class="pure-form pure-form-stacked" enctype="multipart/form-data" method="post" action="test.html">
 <div class="pure-g">
 <div class="pure-u-1 pure-u-md-1-2">
 <label for="field_firstname">Firstname</label>
 <input type="text" id="field_firstname" name="field_firstname" class="pure-u-23-24" tabindex="1">
 <div class="pure-u-1 pure-u-md-1-2">
 <label for="field_lastname">Lastname</label>
 <input type="text" id="field_lastname" name="field_lastname" class="pure-u-23-24" tabindex="2">
 <div class="pure-u-1 pure-u-md-1-2">
 <label for="field_email">E-mail</label>
 <input type="text" id="field_email" name="field_email" class="pure-u-23-24" tabindex="3">
 <div class="pure-u-1 pure-u-md-1-2">
 <label for="field_organisation">Organisation</label>
 <input type="text" id="field_organisation" name="field_organisation" class="pure-u-23-24" tabindex="4">
 <legend>Types of presentations</legend>
 <label for="pres_type_1" class="pure-radio">
 <input type="radio" id="pres_type_1" name="pres_type" value="lecture" tabindex="5" checked> Lectures
 <label for="pres_type_2" class="pure-radio">
 <input type="radio" id="pres_type_2" name="pres_type" value="seminar" tabindex="6"> Seminaries
 <label for="pres_type_3" class="pure-radio">
 <input type="radio" id="pres_type_3" name="pres_type" value="discussion" tabindex="7"> Discussions
 <label for="field_pres_title">Title for lecture/seminarie</label>
 <input type="text" id="field_pres_title" name="field_pres_title" class="pure-u-23-24" tabindex="8">
 <legend>Other information</legend>
 <label for="field_message">Information to the organizer (max 200 characters)</label>
 <textarea id="field_message" name="field_message" cols="50" rows="4" class="pure-u-23-24" tabindex="9"></textarea>
 <button type="submit" id="saveForm" name="saveForm" class="pure-button pure-button-primary" tabindex="10">Send request</button>
 <!--END .content-->
 <script src="scripts/validate.js"></script>


I want to do some form control. Want to check if the entered data are in the correct form.

The section “Contact” section must be completely filled in.

E mail adress in a correct format

This filed “Information to the organizer (max 200 characters)” is not reqiured. But if used, the maximum characters are max 200 charactwers.

When the tickboxes Seminaries or Discussions are choosen the “Information to the organizer (max 200 characters)” must be entered.

I want to have a .js file to do this.

I found something, like this (do not understand it realy)

var pattern = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
var isValid = pattern.test(email);

Can anyone help me out? PLEASE, with codes. Js is totaly new for me.

The code you provided is checking whether a given email address is valid or not by using a regular expression pattern. The regular expression pattern is:


The ^ character at the beginning of the pattern indicates that the email address should start with the specified pattern.

([a-zA-Z0-9_.-])+ specifies that one or more characters in the email address can be either alphabets, digits, underscores, periods, or hyphens. This pattern is repeated twice, separated by the @ symbol.

The @ symbol is followed by ([a-zA-Z0-9_.-])+, which specifies that one or more characters in the domain name can be either alphabets, digits, underscores, periods, or hyphens.

\. specifies a literal period, which separates the domain name from the top-level domain name (TLD).

([a-zA-Z])+ specifies that the TLD must be one or more alphabets.

The + at the end of the pattern indicates that the previous pattern should be matched one or more times.

The test method is called on the pattern regular expression object with the email variable passed as an argument. If the email address matches the pattern, then isValid will be true, otherwise isValid will be false.