JSFiddle - React, Tailwind, and code Playground

by Sergey Denisov

HTML

<h3 id="forms">Forms</h3>
<div class="forms">
  <form>
    <div class="input">
      <input placeholder="name" name="name" type="text" oninput="checkname(this.id)" id="name">
      <div>
        <p id="namereaction" class="reaction"></p>
      </div>
    </div>
    <div class="input">
      <input type="submit" name="submit" value="submit">
    </div>
  </form>
</div>

CSS

@font-face {
  font-family: "Aqua";
  src: url(http://north-wind.be/css/aqua.ttf) format("truetype");
}

.input {
  width: 100%;
  overflow: auto;
  margin: 24px auto;
  font-family: Aqua, Arial;
}

.input input[type=text],
.input input[type=email] {
  border: 1pt solid limegreen;
  width: 150px;
  border-radius: 8px 0px 0px 8px;
  height: 40px;
  margin: 0;
  float: left;
  font-size: 20px;
}

.input div {
  border-radius: 0px 8px 8px 0px;
  width: 350px;
  background: limegreen;
  color: white;
  height: 36px;
  float: left;
  padding: 4px 0;
  margin: 0;
  vertical-align: middle;
}

.input div p {
  vertical-align: middle;
  text-align: center;
  margin: 0 auto;
  border: none;
  padding: 0;
  width: 100%;
  height: 100%;
  font-size: 12px;
  color: white;
}

JavaScript

function checkname(id) {
  var error = "";
  var value = document.getElementById(id).value;
  if (value.length < 1) {
    error = "Please fill in your (first)name.";
  }
  if (value.length > 50) {
    error = "Please fill in your (first)name. Your name is to long.";
  }
  if (value.indexOf("@") > -1) {
    error = "I think you are filling in your emailadress";
  }
  if (value.indexOf(".") > -1) {
    error = "Please check your (first)name, most names don't have a '.'.";
  }
  if (value.indexOf("/") > -1) {
    error = "Please check your (first)name, most names don't have a '/'.";
  }
  var matches = value.match(/\d+/g);
  if (matches != null) {
    error = "Please check your (first)name, we are all people, our (first)name doesn't contain a number.";
  }
  
  var element = document.getElementById(id + 'reaction');
  if (error.length > 1) {
    element.innerHTML = error;
  } else {
    element.innerHTML = '';
  }
  element.style.display = 'none';
	element.offsetHeight;
	element.style.display = '';
}