Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
credit-card-input-mask
Advanced tools
Restrict inputs to certain valid characters (e.g. formatting phone or card numbers)
forked from braintree/restricted-input
Allow restricted character sets in input
elements.
$ npm install --save credit-card-input-mask
import CreditCardInputMask from "credit-card-input-mask";
const formattedCreditCardInput = new CreditCardInputMask({
element: document.querySelector("#credit-card"),
pattern: "{{9999}} {{9999}} {{9999}} {{9999}}",
});
Patterns are a mixture of Placeholder
s and PermaChar
s.
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-Za-z]/
. e.g. {{C}}
will match one alpha character./[0-9]/
. e.g. {{3}}
will match one digit.*
character that matches /./
. e.g. {{*}}
will match the next character.A PermaChar
is the part of the pattern that is automatically inserted. PermaChar
s are defined in the pattern as any characters other than Placeholder
s.
Some example patterns with behavior are listed:
12{{3}}
12
.{{A}}BC
BC
.${{*2L}}E
$
.E
.If an input is changed via a paste event, you may want to adjust the pattern before input formatting occurs. In this case, pass an onPasteEvent
callback:
const formattedCreditCardInput = new RestrictedInput({
element: document.querySelector('#credit-card'),
pattern: '{{9999}} {{9999}} {{9999}} {{9999}}',
onPasteEvent: function (payload) {
var value = payload.unformattedInputValue;
if (requiresAmexPattern(value)) {
formattedCreditCardInput.setPattern('{{9999}} {{999999}} {{99999}}')
} else {
formattedCreditCardInput.setPattern('{{9999}} {{9999}} {{9999}} {{9999}}')
}
})
});
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. |
onPasteEvent | Function (optional) | A callback function to inspect the unformatted value of the input during a paste event. See Paste Event. |
input
elements.3.0.1
supports-input-formatting
module at top levelFAQs
Restrict inputs to certain valid characters (e.g. formatting phone or card numbers)
The npm package credit-card-input-mask receives a total of 242 weekly downloads. As such, credit-card-input-mask popularity was classified as not popular.
We found that credit-card-input-mask demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.