auto-formatter


Format as you type.
- phone number
(XXX) XXX-XXXX, XXXXX-XXXXX
- credit card number
XXXX XXXX XXXX XXXX, XXXX XXXXXX XXXXX
- date
DD/MM/YYYY, MM/DD/YYYY, YYYY/MM/DD

Usage:
<input type="tel" id="mobile-number" value="1234567890" data-format="(XXX) XXX-XXXX">
<script src="path/to/auto-formatter.js"></script>
<script>
var phoneNumberFormatter;
phoneNumberFormatter = new AutoFormatter({
targetNode: document.querySelector('#phone-number'),
limitToMaxLength: true
});
phoneNumberFormatter.enableFormatting();
AutoFormatter.format({
value: '1234567890',
format: 'XXXXX-XXXXX'
});
</script>
API
targetNodeFormatter = new AutoFormatter({
targetNode: targetNode,
limitToMaxLength: limitToMaxLength,
recurringPattern: recurringPattern,
direction: direction
})
targetNodeFormatter.enableFormatting();
targetNodeFormatter.disableFormatting();
AutoFormatter.format({
value: value,
format: format,
limitToMaxLength: limitToMaxLength,
recurringPattern: recurringPattern,
direction: direction
})
License
Copyright 2015, Yahoo Inc. Copyrights licensed under the MIT License. See the accompanying LICENSE file for terms.