JSPM

credit-card-input-mask

2.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 815
  • Score
    100M100P100Q115207F
  • License MIT

Restrict inputs to certain valid characters (e.g. formatting phone or card numbers)

Package Exports

  • credit-card-input-mask

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (credit-card-input-mask) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

credit-card-input-mask

forked from braintree/restricted-input

Allow restricted character sets in input elements.

Usage

import RestrictedInput from 'restricted-input';

const formattedCreditCardInput = new RestrictedInput({
  element: document.querySelector('#credit-card'),
  pattern: '{{9999}} {{9999}} {{9999}} {{9999}}'
});

Demo

Patterns

Patterns are a mixture of Placeholders and PermaChars.

Placeholder

A Placeholder is the part of the pattern that accepts user input based on some restrictions. A placeholder is defined in the pattern using two open curly brackets, the placeholder, followed by two closing curly brackets e.g. {{Abc123}}.

The patterns a Placeholder can be are:

  • a single alpha character that matches the alpha regex /[A-Za-z]/. e.g. {{C}} will match one alpha character.
  • a single digit that matches the digit regex /[0-9]/. e.g. {{3}} will match one digit.
  • a * character that matches /./. e.g. {{*}} will match the next character.

PermaChar

A PermaChar is the part of the pattern that is automatically inserted. PermaChars are defined in the pattern as any characters other than Placeholders.

Example patterns

Some example patterns with behavior are listed:

  • 12{{3}}
    • Inserts 12.
    • Waits for a single digit from the user.
  • {{A}}BC
    • Waits for a single alpha from the user.
    • Inserts BC.
  • ${{*2L}}E
    • Inserts $.
    • Waits for any single character input from the user.
    • Waits for a single digit from the user.
    • Waits for a single alpha from the user.
    • Inserts E.

API

options

Key Type Description
element HTMLInputElement or HTMLTextAreaElement A valid reference to an input or textarea DOM node
pattern String Pattern describing the allowed character set you wish for entry into corresponding field. See Patterns.