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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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 style="padding-left:10%">
  <form onsubmit="validateInput(event)">
    <br>
    <p>Please enter your name</p>
    
    <input 
      id="fname" 
      placeholder="First"
    />

    <p 
       id="fname-msg"
       style="color:red"
    ></p>
    
    <input 
      id="mname" 
      placeholder="Middle"
    />
    
    <p 
       id="mname-msg"
       style="color:red"
    ></p>

    <input 
      id="lname" 
      placeholder="Last"
    />

    <p 
       id="lname-msg"
       style="color:red"
    ></p>
    
    <p id="result-msg"></p>
    
    <button type="submit">Submit</button>
  </form>
</div>

<script src="https://cdn.jsdelivr.net/npm/rj-validate@1.5.0/dist/rj.min.js"></script>
              
            
!

CSS

              
                
              
            
!

JS

              
                function validateInput(event) {
  event.preventDefault();
  
  var fname = document.getElementById('fname');
  var mname = document.getElementById('mname');
  var lname = document.getElementById('lname');
  
  var result = rj().validateAll([
      {
          name: 'first name',
          value: fname.value,
          rules: {
              required: true,
              min: 2,
              alpha: true
          },
      },

      {
          name: 'middle name',
          value: mname.value,
          rules: {
              min: 2,
              alpha: true
          }
      },

      {
          name: 'last name',
          value: lname.value,
          rules: {
              required: true,
              min: 2,
              alpha: true
          }
      }
  ]);

  if (result.valid) {
    var textColor = 'green';
    var output_msg = 'All tests pass';
  } else {
    var textColor = 'red';
    var output_msg = '<br>-- There was an error submitting your information. Please check above for more details --';
  }
  
  var msgDiv = document.getElementById('result-msg');
  msgDiv.style.color = textColor;
  msgDiv.innerHTML = output_msg;
    
  var fname_msg = document.getElementById('fname-msg');

  if (result['first name'].valid) {
    fname_msg.innerHTML = ' ';
  } else {
    fname_msg.innerHTML = result['first name'].message;
  }

  var mname_msg = document.getElementById('mname-msg');

  if (result['middle name'].valid) {
    mname_msg.innerHTML = '';
  } else {
    mname_msg.innerHTML = result['middle name'].message;
  }

  var lname_msg = document.getElementById('lname-msg');

  if (result['last name'].valid) {
    lname_msg.innerHTML = '';
  } else {
    lname_msg.innerHTML = result['last name'].message;
  }
}
              
            
!
999px

Console