Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="container">
  <div class="row">
    <div class="col-sm-12">
      <div class="form-wrapper">
        <form id="registration_form" onsubmit="return validation(event)">
          <h3 class="title">Enter your Detail to Register</h3>
          <hr>
          <div id="error-message" class="notification-div">
          </div>
          <div class="success-message" class="notification-div"></div>
          <div class="form-row">
            <div class="form-group col-md-6">
              <label for="emailAddress">Email*</label>
              <input type="email" class="form-control" id="emailAddress" name="email" placeholder="Email">
              <span id="error-email" class="error-span"></span>
            </div>
            <div class="form-group col-md-6">
              <label for="inputPassword">Password*</label>
              <input type="password" class="form-control" id="inputPassword" name="password" placeholder="Password">
              <span id="error-password" class="error-span"></span>
            </div>
          </div>
          <div class="form-group">
            <label for="inputAddress">Address*</label>
            <input type="text" class="form-control" id="inputAddress" name="address" placeholder="1234 Main St">
            <span id="error-address" class="error-span"></span>
          </div>
          <div class="form-group">
            <label for="inputAddress2">Address 2</label>
            <input type="text" class="form-control" id="inputAddress2" name="address2" placeholder="Apartment, studio, or floor">
            <span id="error-address" class="error-span"></span>
          </div>
          <div class="form-row">
            <div class="form-group col-md-6">
              <label for="inputCity">City</label>
              <input type="text" class="form-control" id="inputCity" name="city">
              <span id="error-city" class="error-span"></span>
            </div>
            <div class="form-group col-md-4">
              <label for="inputState">State*</label>
              <span id="error-state" class="error-span"></span>
              <select id="inputState" class="form-control" name="state">
                <option selected>Province 1</option>
                <option>Province 2</option>
                <option>Province 3</option>
                <option>...</option>
              </select>
            </div>
            <div class="form-group col-md-2">
              <label for="inputZip">Zip*</label>
              <input type="text" class="form-control" id="inputZip" name="zip">
              <span id="error-zip" class="error-span"></span>
            </div>
          </div>
          <button type="submit" class="btn btn-primary">Sign in</button>
        </form>
      </div>
    </div>
  </div>
</div>
              
            
!

CSS

              
                body {
  font-family: "Roboto", sans-serif;
}

.form-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

.title {
  align-items: center;
}

.notification-div {
  color: #333333;
  margin: 15px;
  box-shadow: 0px 10px 17px rgb(204, 204, 204);
  font-weight: 600;
  transition: all 0.7s ease;
  background: #ffdde2;
  padding: 20px;
  margin-bottom: 30px;
  display: none;
}

.error-span {
  color: #cc1212;
  font-size: 13px;
}

              
            
!

JS

              
                function validation(event) {
  event.preventDefault();

  const regex = {
    zip: /^\d{6}$/,
    email: /[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}/gi,
    address: /\b[a-zA-Z0-9\s]+\b/g,
    password: /^\w+$/
  };
  var zipcode_value = document.getElementById("inputZip").value;
  var emailAddress = document.getElementById("emailAddress").value;
  var passwordElement = document.getElementById("inputPassword");
  var inputPassword = passwordElement.value;
  var inputAddress = document.getElementById("inputAddress").value.trim();
  var inputAddress2 = document.getElementById("inputAddress2").value;
  var cityinput = document.getElementById("inputCity").value;
  var formerror = false;

  if (!regex.zip.test(zipcode_value)) {
    document.getElementById("error-zip").innerHTML = "Enter the Valid Zip Code";
    document.getElementById("inputZip").focus();
    formerror = true;
  }

  if (cityinput == "") {
    console.log("city is empty");
    document.getElementById("inputCity").focus();
    document.getElementById("error-city").innerHTML = "Enter the city Name";
    formerror = true;
  }

  if (cityinput) {
    cityinput = cityinput.trim();
  }

  if (inputAddress == "") {
    document.getElementById("error-address").innerHTML =
      "Address field is compulsory";
    document.getElementById("inputAddress").focus();
  }

  if (inputAddress) {
    inputAddress = inputAddress.trim();
    if (inputAddress.length < 4) {
      document.getElementById("error-address").innerHTML =
        "Adress should be atleast 6 character long";
      formerror = true;
    }
    if (!regex.address.test(inputAddress)) {
      document.getElementById("error-address").innerHTML =
        "Only alphabet, digits are allowable";
      formerror = true;
    }
  }

  if (inputAddress2) {
    inputAddress2 = inputAddress2.trim();
  }

  if (!regex.password.test(inputPassword)) {
    passwordElement.focus();
    document.getElementById("error-password").innerHTML =
      "password should only be alphabet, digit or underscore";
    formerror = true;
  }

  if (inputPassword != "") {
    if (inputPassword.length < 6) {
      passwordElement.focus();
      document.getElementById("error-password").innerHTML =
        "password should be atleast six character";
      formerror = true;
    }

    if (inputPassword == emailAddress) {
      passwordElement.focus();
      document.getElementById("error-password").innerHTML =
        "Password cannot be Username";
      passworderror = true;
    }
  }

  if (emailAddress == "") {
    document.getElementById("emailAddress").focus();
    document.getElementById("error-email").innerHTML =
      "Email address cannot be blank";
    formerror = true;
  }

  if (emailAddress) {
    emailAddress = emailAddress.trim();
    if (!regex.email.test(emailAddress)) {
      document.getElementById("emailAddress").focus();
      document.getElementById("error-email").innerHTML =
        "Not a Valid Email Adress";
      formerror = true;
    }
  }

  if (formerror) {
    var error_message = document.getElementById("error-message");
    error_message.style.display = "block";
    error_message.innerHTML =
      "There is error on Form !!! Please Correct it before submitting again";
    return false;
  }

  var form = document.getElementById("registration_form");
  var formdata = new FormData(form);

  fetch("/echo", {
    method: "POST",
    body: formdata
  })
    .then((response) => response.text())
    .then((text) => console.log(text))
    .catch((error) => console.error(error));
}

              
            
!
999px

Console