Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <form id="example_form">
  <div class="form-group">
    <label for="email">Email address</label>
    <input type="email" class="form-control" id="email" placeholder="Email address" aria-required="true" aria-invalid="false" required>
  <button type="submit" class="btn btn-default" id="validate">Validate</button>
<small>Test API key always returns Valid</small>
              body {
  padding: 5%;
#email {
  margin-bottom: 20px;

              // Replace with your API key, test key will always return true regardless of email address
var api_key = "PCW45-12345-12345-1234X";

var example_form = document.getElementById("example_form");

example_form.addEventListener("submit", function(e) {
  var email_field = document.getElementById("email");

function validate_email(element) {
  // Grab the input text and trim any whitespace
  var email_address = element.value.trim();

  if (email_address != "") {
    // Remove any previous validation results
    var email_valid = document.getElementById("email_valid");
    if (email_valid) {

    // Create a template bootstrap alert div
    var response_html = document.createElement("div");
    response_html.setAttribute("class", "alert");
    response_html.setAttribute("role", "alert");
    response_html.setAttribute("id", "email_valid");

    // Create the URL including API key and encoded email address
    var email_url =
      "https://ws.postcoder.com/pcw/" +
      api_key +
      "/emailaddress/" +

    // Create a loading message
    var loading_html = document.createElement("div");
    loading_html.setAttribute("id", "email_loading");
    loading_html.textContent = "Validating email address...";

    element.insertAdjacentElement("afterend", loading_html);
    // Call the API
    var email_request = new XMLHttpRequest();
    email_request.open("GET", email_url, true);

    email_request.onload = function() {
      if (email_request.status >= 200 && email_request.status < 400) {
        var data = JSON.parse(email_request.responseText);

        if (data.alternative) {
          // Add relevant class and message to alert template
          response_html.textContent =
            "Did you mean: " + data.alternative + "? ";

          // Different role for ARIA, as the alert has an interactive element
          response_html.setAttribute("role", "alertdialog");
          // Create a button to help user swap to suggestion easily
          var change_button = document.createElement("button");
          change_button.setAttribute("class", "btn btn-default");
          change_button.setAttribute("type", "button");
          change_button.textContent = "Yes";
          change_button.onclick = function(e) {
            // Swaps the current input for the suggestion and re-run validation
            element.value = data.alternative;
          // Add button to alert template
          // Add alert to page after email field element
          element.insertAdjacentElement("afterend", response_html);
        } else {
          if (data.valid === true) {
            // Add relevant class and message to alert template
            response_html.textContent = "Email address valid";
            // Add alert to page after email field element
            element.insertAdjacentElement("afterend", response_html);

            // Set ARIA-invalid attribute of field to false (means it is NOT invalid)
            element.setAttribute("aria-invalid", "false");
            // Note: If "score" is less 100, it may be a generic sales@ mailbox, disposable email address or a catch all server
            // More info - https://www.alliescomputing.com/support/validating-email-addresses
          } else {
            // Add relevant class and message to alert template
            response_html.textContent =
              "Email address not valid: " + data.state;
            // Add alert to page after email field element
            element.insertAdjacentElement("afterend", response_html);

            // Set ARIA-invalid attribute of field to true (means it IS invalid)
            element.setAttribute("aria-invalid", "true");
            // Full list of "state" responses - https://developers.alliescomputing.com/postcoder-web-api/email-validation
      } else {

        // Triggered if API does not return HTTP code between 200 and 399
        // More info - https://developers.alliescomputing.com/postcoder-web-api/error-handling

    email_request.onerror = function() {
      // Triggered if API cannot be reached
      // More info - https://developers.alliescomputing.com/postcoder-web-api/error-handling

🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.