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

              
                 <!-- tabs -->
    <div class="input-settings">
      <ul class="tabs">
        <li class="tab digits active">
          <span class="title">Digits</span>
        </li>
        <li class="tab letters">
          <span class="title">Letters</span>
        </li>
        <li class="tab yours">
          <span class="title">Yours</span>
        </li>
        <div class="slider"></div>
      </ul>
    </div>
    <!-- END tabs -->

    <!-- custom regular expression input -->
    <div class="my-reg-ex-container">
      <input class="my-reg-ex" type="text" />
    </div>
    <!--END custom regular expression input -->

    <!-- input -->
    <input class="primary" type="text" />
    <!--END input -->

    <!-- made in jssecrets.com -->
    <a class="jssecrets" href="https://jssecrets.com/" target="_blank"
      >jssecrets.com</a
    >
    <!-- made in jssecrets.com -->
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;800&display=swap");
@import url("https://fonts.googleapis.com/css2?family=Urbanist:wght@500&display=swap");
*,
::before,
::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Poppins", sans-serif;
}

ul {
  list-style: none;
}

body {
  height: 100vh;
  background: hsl(225, 14%, 12%);
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  color: #292d34;
}

input.primary {
  width: 320px;
  border: 2px solid rgb(80, 121, 247);
  box-shadow: 0 4px 20px rgba(80, 121, 247, 0.4);
  color: rgb(80, 121, 247);
  background: transparent;
  outline: none;
  font-size: 24px;
  padding: 16px;
  border-radius: 12px;
  transition: all 0.8s ease-out;
  opacity: 1;
}
@media (max-width: 400px) {
  input.primary {
    width: 220px;
    padding: 8px;
  }
}

.input-settings {
  width: 320px;
  border-radius: 10px;
  background-color: hsl(225, 14%, 17%);
  border: 1.5px solid rgba(0, 0, 0, 0.38);
  box-shadow: 0 8px 32px 0 hsl(225, 14%, 12%);
  backdrop-filter: blur(40px);
  padding: 16px;
  position: absolute;
  left: 50%;
  top: 5%;
  transform: translate(-50%, -5%);
  opacity: 1;
  transition: all 0.7s ease-out;
}
@media (max-width: 400px) {
  .input-settings {
    width: 220px;
    padding: 8px;
  }
}

.my-reg-ex-container {
  position: absolute;
  left: 50%;
  top: 21.4%;
  transform: translate(-50%, -5%);
  width: 320px;
  transition: all 0.5s ease-out;
}
@media (max-width: 400px) {
  .my-reg-ex-container {
    width: 220px;
  }
}
.my-reg-ex-container .my-reg-ex {
  width: 100%;
  border-radius: 10px;
  border: 2px solid #f7ce51;
  box-shadow: 0 4px 20px rgba(245, 205, 81, 0.4);
  color: #f7ce51;
  background: transparent;
  outline: none;
  font-size: 24px;
  padding: 16px;
  border-radius: 12px;
  transition: all 0.5s ease-out;
  opacity: 0;
  transform: translateY(-20px);
}
@media (max-width: 400px) {
  .my-reg-ex-container .my-reg-ex {
    padding: 8px;
  }
}
.my-reg-ex-container.active .my-reg-ex {
  opacity: 1;
  transform: translateY(0);
}

.tabs {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}
.tabs .slider {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 100%;
  width: 33.33333%;
  background: linear-gradient(45deg, rgb(245, 205, 81) 0%, rgb(247, 206, 81) 100%);
  box-shadow: 0 4px 20px rgba(245, 205, 81, 0.4);
  border-radius: 9px;
  z-index: 0;
  transition: all 0.3s linear;
}
.tabs .tab {
  width: 50%;
  height: 100%;
  display: block;
  text-align: center;
  cursor: pointer;
  padding: 16px 0 16px 0;
  border-radius: 9px;
  font-size: 16px;
  z-index: 1;
  position: relative;
  color: #7c828d;
  transition: all 0.3s linear;
}
.tabs .tab:hover {
  color: #f7ce51;
}
.tabs .tab .title {
  font-size: 16px;
}
@media (max-width: 400px) {
  .tabs .tab .title {
    font-size: 14px;
  }
}
.tabs .tab.active .title {
  font-weight: 900;
  color: hsl(225, 14%, 12%);
}
.tabs .tab:nth-of-type(1).active ~ .slider {
  left: 0;
}
.tabs .tab:nth-of-type(2).active ~ .slider {
  left: 33.33333%;
}
.tabs .tab:nth-of-type(3).active ~ .slider {
  left: 66.6666%;
}

.jssecrets {
  font-weight: 500;
  text-decoration: none !important;
  font-family: "Urbanist";
  padding: 16px;
  background: #ffc805;
  color: #000000;
  font-size: 1.2em;
  letter-spacing: 0.2px;
  border-radius: 8px;
  box-shadow: 0px 4px 12px rgba(184, 144, 0, 0.1882352941), 0px 8px 24px rgba(184, 144, 0, 0.3764705882);
  position: absolute;
  bottom: 24px;
  right: 24px;
  transition: all 0.3s;
}

.jssecrets:hover {
  transform: translateY(-4px);
}
              
            
!

JS

              
                // Variables
const tabs = document.querySelectorAll('.tabs .tab');
const input = document.querySelector('.primary');
const myRegExInput = document.querySelector('.my-reg-ex');
const myRegExContainer = document.querySelector('.my-reg-ex-container');

// Regular Expressions

// digits only
let regex = /\d/;
// any character
let myRegEx = /./;

// Functions
// 1. Set active tab
const setActiveTab = (event) => {
  // sliding tabs functionality
  document.querySelector('.tab.active').classList.remove('active');
  event.currentTarget.classList.add('active');
  //

  // clear input
  input.value = '';

  if (event.currentTarget.classList.contains('digits')) {
    // allow digits only
    regex = /\d/;
    // hide custom regex input
    myRegExContainer.classList.remove('active');
  } else if (event.currentTarget.classList.contains('letters')) {
    // allow uppercase and lowercase letters only
    regex = /[A-Za-z]/;
    // hide custom regex input
    myRegExContainer.classList.remove('active');
  } else {
    // allow allow any character
    regex = myRegEx;
    // show custom regex input
    myRegExContainer.classList.add('active');
  }
};

// 2. Input filter
const inputFilter = (event, regEx) => {
  // catch pressed key's code
  // and convert it to an actual character
  let symbol = String.fromCharCode(event.keyCode);

  // if character doesn't belong to regEx set
  // then prevent it from being typed
  if (!regEx.test(symbol)) {
    event.preventDefault();
  }
};

// 3. Input event
const inputEvent = (event) => {
  inputFilter(event, regex);
};

// 4. Setting user's input filter
const inputUserChoice = (event) => {
  // create and assign user's input to regEx
  myRegEx = new RegExp(`[${event.currentTarget.value}]`);
  regex = myRegEx;
};

// 5. Emptiness validation
const ifEmpty = (event) => {
  // custom regEx is empty
  // then allow any character
  if (
    !event.currentTarget.value.trim().length ||
    event.currentTarget.value === ''
  ) {
    regex = /./;
  }
};

// Event Listeners
// sliding tabs event
tabs.forEach((tab) => {
  tab.addEventListener('click', setActiveTab);
});
// input event
input.addEventListener('keypress', inputEvent);
// user's regEx
myRegExInput.addEventListener('input', inputUserChoice);
// check whether empty on blur
myRegExInput.addEventListener('blur', ifEmpty);

              
            
!
999px

Console