cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

            
              <div class="container">
<div class="row">
  <h1>HTML5 Form Validation Patterns</h1>

  <section class="description note">
    <h3>Validation</h3>
    <p>HTML5 adds JavaScript free, client-side form-validation that can help ensure that input text conforms to a specified format. </p>
    <p>On the input elements we add the <code>pattern</code> attribute and use <a href="https://www.w3schools.com/jsref/jsref_obj_regexp.asp" target="_blank">Regular Expressions</a> to specify the pattern. </p>

  </section>
</div>

  <div class="row">
  <section class="description">
    <h3>London phone number following the pattern <code>+44-20-1234-1234</code></h3>
    <p>This is a pattern that requires a set of defined characters at the start – <code>+44-20-</code> – and then two sets of four digits separated by a dash.</p>
    <p>Because special characters like '+' and '-' might be misinterpreted we put them in square brackets and precede them with a '\' - e.g. <code>[\+]</code>.</p>

    <p>To only accept digits we use <code>[0-9]</code>and to specify the amount of digits we want we use curly brackets containing the number – <code>{4}</code>.</p>
    <p>To accept four digits we use <code>[0-9]{4}</code>.</p>

    <p>The pattern we use here is <code>[\+]44[\-]20[\-][0-9]{4}[\-][0-9]{4}</code> </p>


    <form action="">
      <div class="form-group">


        <label for="phone"></label>
        <input type="tel" class="form-control input-lg" id="phone" placeholder="Enter phone number" pattern="[\+]44[\-]20[\-][0-9]{4}[\-][0-9]{4}" required>
      </div>

      <button class="btn btn-primary">Submit</button>
      <small>Will only submit if valid</small>

    </form>
  </section>
  <!-- end "description" -->
</div>
  
  <div class="row">
  <section class="description">
    <h3>US Passport Number following the pattern <code>A1234567</code></h3>

    <p>To specify upper case letters we use <code>[A-Z]</code>and to specify the amount of letters we want we use curly brackets containing the number – <code>{1}</code>.</p>
    <p>To accept one letter we use <code>[A-Z]{1}</code>.</p>

    <p>The pattern we use here is <code>[A-Z]{1}[0-9]{7}</code>. </p>


    <form action="">
      <div class="form-group">


        <label for="phone"></label>
        <input type="text" class="form-control input-lg" id="phone" placeholder="Enter passport number" pattern="[A-Z]{1}[0-9]{7}" required>
      </div>

      <button class="btn btn-primary">Submit</button>
      <small>Will only submit if valid</small>

    </form>
  </section>
  <!-- end "description" -->
</div>
  
  <div class="row">
  <section class="description note">
    <h3>Note on Shorthand</h3>
    <p><code>[0-9]</code> can be replaced by the shorthand <code>\d</code></p>
    <p><em>Using the shorthand our first example would be <code>[\+]44[\-]20[\-]\d{4}[\-]\d{4}</code></em> </p>
    <p><code>[A-Z]</code> can be replaced by the shorthand <code>\w</code></p>
    <p><em>Using the shorthand our second example would be <code>\w{1}\d{7}</code></em> </p>
    <p>If spaces are required use the shorthand <code>\s</code></p>
    <p>Check out <a href="http://regexr.com/" target="_blank">RegExr</a> for more examples.</p>

  </section>
  <!-- end "description" -->
</div>

</div>
            
          
!
            
              $main-color: #F6F6F6;

body {
  background: darken($main-color, 5%);
  color: darken($main-color, 30%);

}

.description {
  background: lighten($main-color, 15%);
  padding: .7em;
  margin: .5em 0 0 0;
}

.note {
  background: lighten($main-color, 5%);
}

em {
  margin: 0 0 0 .3em;
}

h1, h3 {
  color: darken($main-color, 45%);
}
            
          
!
999px
🕑 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.
Loading ..................

Console