formatter.js

Format user input to match a specified pattern

View the Project on GitHub firstopinion/formatter.js

Demos

Credit Card

Ex: 4242-4242-4242-4242

new Formatter(document.getElementById('credit-input'), {
  'pattern': '{{9999}}-{{9999}}-{{9999}}-{{9999}}'
});
$('#credit-input').formatter({
  'pattern': '{{9999}}-{{9999}}-{{9999}}-{{9999}}'
});

Phone Number

Ex: (802) 415-3411

new Formatter(document.getElementById('phone-input'), {
  'pattern': '({{999}}) {{999}}.{{9999}}',
  'persistent': true
});
$('#phone-input').formatter({
  'pattern': '({{999}}) {{999}}-{{9999}}',
  'persistent': true
});