Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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

              
                <label for="phone-numer">Phone Number</label>
<div class="phone-number-input">
  <input id="phone-number" type="text" placeholder="(555) 555-5555">
  <label class="valid" for="phone-number">
    <svg width="28px" height="28px" viewBox="0 0 28 28" version="1.1">
      <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
        <g transform="translate(-890.000000, -623.000000)" fill="#FFFFFF" opacity="0.9">
          <g transform="translate(524.000000, 468.000000)">
            <g transform="translate(366.000000, 155.000000)">
              <path d="M9.97374888,20.6610254 L11.2477328,21.9350092 L22.4350092,10.7477328 L20.3071035,8.61982707 L11.2477328,17.6791979 L7.62790569,14.0593708 L5.5,16.1872765 L9.97374888,20.6610254 Z M13.8863076,27.3315173 C21.3118918,27.3315173 27.3315173,21.3118918 27.3315173,13.8863076 C27.3315173,6.46072329 21.3118918,0.441097862 13.8863076,0.441097862 C6.46072329,0.441097862 0.441097862,6.46072329 0.441097862,13.8863076 C0.441097862,21.3118918 6.46072329,27.3315173 13.8863076,27.3315173 Z"></path>
            </g>
          </g>
        </g>
      </g>
    </svg>
  </label>
  <label class="invalid" for="phone-number">
    <svg width="28px" height="28px" viewBox="0 0 28 28" version="1.1">
      <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
        <g transform="translate(-930.000000, -623.000000)" fill="#FFFFFF" opacity="0.9">
          <g transform="translate(524.000000, 468.000000)">
            <g transform="translate(406.000000, 155.000000)">
              <path d="M16.0142133,13.8863076 L20.5438986,9.35662218 L18.415993,7.22871648 L13.8863076,11.7584019 L9.35662218,7.22871648 L7.22871648,9.35662218 L11.7584019,13.8863076 L7.22871648,18.415993 L9.35662218,20.5438986 L13.8863076,16.0142133 L18.415993,20.5438986 L20.5438986,18.415993 L16.0142133,13.8863076 Z M13.8863076,27.3315173 C21.3118918,27.3315173 27.3315173,21.3118918 27.3315173,13.8863076 C27.3315173,6.46072329 21.3118918,0.441097862 13.8863076,0.441097862 C6.46072329,0.441097862 0.441097862,6.46072329 0.441097862,13.8863076 C0.441097862,21.3118918 6.46072329,27.3315173 13.8863076,27.3315173 Z"></path>
            </g>
          </g>
        </g>
      </g>
    </svg>
  </label>
</div>
              
            
!

CSS

              
                input:not([data-validation="valid"]) ~ label.valid,
input:not([data-validation="invalid"]) ~ label.invalid {
  display: none;
}

// NON-ARTICLE STYLES

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  font-size: 16px;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  
  font-family: 'Open Sans', sans-serif;
  line-height: 1.5rem;
  
  background: linear-gradient(to bottom, #0CC8A1, #383194);
}

label {
  margin-bottom: 0.25rem;
  
  color: transparentize(white, 0.1);
  font-size: 1rem;
  line-height: 1.5rem;
  font-weight: 600;
}

input {
  width: 100%;
  display: block;
  
  font-size: 1.65rem;
  line-height: 2rem;
  
  border-radius: 0.25rem;
  outline: none;
  padding: 0.375rem;
  
  background-color: transparentize(white, 0.9);
  border: 2px solid transparentize(white, 0.5);
  color: transparentize(white, 0.1);
  font-weight: 300;
  text-align: center;
  
  &::placeholder {
    color: transparentize(white, 0.7);
  }
  
  &:focus::placeholder {
    color: transparent;
  }
}

.phone-number-input {
  width: 22rem;
  max-width: 100%;
  position: relative;
  
  // Add a little extra padding to the bottom of the input to vertically center it.
  padding-bottom: 1.5rem;
  
  .valid, .invalid {
    position: absolute;
    top: calc(0.625rem + 2px);
    right: calc(0.625rem + 2px);
    border-radius: 100%;
    width: 1.75rem;
    height: 1.75rem;
  }
}

.valid {
  color: green;
}

.invalid {
  color: red;
}
              
            
!

JS

              
                $("input").on("input blur", function(event) {
  var value = $(this).val();
  
  if (isPhoneNumber(value)) {
    $(this).attr({ "data-validation": "valid" });
    return;
  }
  
  if (event.type === "blur" && value !== "") {
    $(this).attr({ "data-validation": "invalid" });
  }
  else {
    $(this).removeAttr("data-validation");
  }
});

function isPhoneNumber(string) {
  return /^1?([2-9]\d\d){2}\d{4}$/.test(string.replace(/\D/g, ""));
}
              
            
!
999px

Console