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

<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

  <!-- Bootstrap CSS -->
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
    integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

  <title>Contact Form</title>
</head>

<body>
  <div class="container">
    <div class="row">
      <div class="col-md-6 mx-auto mt-5">
        <h1 class="p-5">👽😅😋👻💩😧😬💀🙌🙀</h1>
        <form action="" method="POST">
          <div class="form-group">
            <label>Name:</label>
            <input type="text" class="form-control" id="name" placeholder="Name">
            <div class="invalid-feedback">
              Name must be between 2 and 20 characters
            </div>
          </div>

          <div class="form-group">
            <label>Email:</label>
            <input type="text" class="form-control" id="email" placeholder="Email address">
            <div class="invalid-feedback">
              Enter a valid email address
            </div>
          </div>

          <div class="form-group">
            <label>Telephone:</label>
            <input type="text" class="form-control" id="phone" placeholder="Phone number">
            <div class="invalid-feedback">
              Enter a valid number
            </div>
          </div>
          <input type="submit" value="Submit" class="btn btn-info btn-block">
        </form>
      </div>
    </div>
  </div>


  <!-- Optional JavaScript -->
  <!-- jQuery first, then Popper.js, then Bootstrap JS -->
  <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
    integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
    crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
    integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
    crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
    integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
    crossorigin="anonymous"></script>
  <script src="index.js"></script>

</body>

</html>

const name = document.getElementById('name');
const email = document.getElementById('email');
const phone = document.getElementById('phone')

name.addEventListener('blur', valName);
email.addEventListener('blur', valEmail);
phone.addEventListener('blur', valPhone);

function valName() {
  const re = /^[a-zA-Z]{2,20}$/;
  if(!re.test(name.value)) {
    name.classList.add('is-invalid');
  } else {
    name.classList.remove('is-invalid');
  }
}

function valEmail() {
  const re = /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/;
  if(!re.test(email.value)) {
    email.classList.add('is-invalid');
  } else {
    email.classList.remove('is-invalid');
  }
}

function valPhone() {
  const re = /^[0-9\-\+]{9,15}$/;
  if(!re.test(phone.value)) {
    phone.classList.add('is-invalid');
  } else {
    phone.classList.remove('is-invalid');
  }
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js
  2. https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.15.0/popper.min.js
  3. https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css