JSPM

  • Created
  • Published
  • Downloads 198497
  • Score
    100M100P100Q164896F
  • License Apache License 2.0

JavaScript library to separate input text content when you are typing

Package Exports

  • cleave.js
  • cleave.js/dist/cleave
  • cleave.js/dist/cleave.js
  • cleave.js/src/shortcuts/CreditCardDetector
  • cleave.js/src/shortcuts/DateFormatter
  • cleave.js/src/shortcuts/PhoneFormatter

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 (cleave.js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Cleave.js

Travis

Cleave.js has a simple purpose: to help you format input text content automatically.

The idea is to provide an easy way to increase readability when you are typing. By using the library, you won't need to write any mind-blowing regular expressions or mask patterns to format input text.

However, this isn't meant to replace any form validation or mask library, you should still validate your data before submitting.

tl;dr the demo page

Features

  • Credit card number formatting
  • Phone number formatting (lib separated by countries to reduce size)
  • Date formatting
  • Customize delimiter, prefix and blocks pattern
  • CommonJS / AMD support

Installation

npm

npm install --save cleave.js

bower

bower install --save cleave.js

TBT

Grab the file from dist folder

Usage

Simply include

<script src="cleave.min.js"></script>
<script src="cleave-phone.{country}.js"></script>

cleave-phone.js is only required when phone shortcut mode is enabled. See more in documentation: phone lib usage section

Then have a text field

<input class="input-phone" type="text"/>

Now in your JavaScript

var cleave = new Cleave('.input-phone', {
    phone:      true,
    regionCode: '{country}'
});

More examples: the demo page

CommonJS

var Cleave = require('cleave.js');
require('cleave.js/dist/vendor/cleave-phone.{country}');

var cleave = new Cleave(...)

AMD

require(['dist/cleave.min', 'dist/vendor/cleave-phone.{country}'], function (Cleave) {
    var cleavePhone = new Cleave(...)
});

Building & Running tests

npm install
gulp build & gulp test

Documentation

References

Licence

Cleave.js is licensed under the Apache License Version 2.0