Get started with vanilla-masker CDN

MIT licensed

Vanilla-Masker: Lightweight JS input masking, no external dependencies.

Tags:
  • mask input
  • javascript
  • lightweight
  • cross-browser
  • cross-device

Stable version

Copied!

How to start using vanilla-masker CDN


<!DOCTYPE html>
<html>
<head>
  <title>Get started with vanilla-masker CDN - cdnhub.io</title>
  <link rel="stylesheet" href="styles.css">
  <script src="https://cdn.cdnhub.io/vanilla-masker/1.2.0/vanilla-masker.min.js"></script>
</head>
<body>
  <input type="text" id="phone" placeholder="Enter phone number" />
  <button id="mask">Mask phone number</button>
  <script>
    document.getElementById('mask').addEventListener('click', function() {
      const phoneInput = document.getElementById('phone');
      MaskedInput.create({
        element: phoneInput,
        mask: ['+', /[1-9]/, '(', /[1-9]/, /[1-9]/, /[1-9]/, /[1-9]/, /[1-9]/, /[1-9]/, /[1-9]/, /[1-9]/, /[1-9]/, /[1-9]/, '-', /[1-9]/, /[1-9]/, /[1-9]/, /[1-9]/, /[1-9]/, /[1-9]/, /[1-9]/, /[1-9]/],
        showMaskOnFocus: false,
        placeholderChar: '_'
      });
    });
  </script>
</body>
</html>
Copied!

All versions