Cleave.js has a simple purpose: to help you format input text content automatically.
TL;DR the demo page
The idea is to provide an easy way to increase input field readability by formatting your typed data. By using this 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 validation or mask library, you should still sanitize and validate your data in backend.
npm install --save cleave.jsbower install --save cleave.jsGrab file from dist directory
Simply include
cleave-phone.{country}.jsaddon is only required when phone shortcut mode is enabled. See more in documentation: phone lib addon section
Then have a text field
Now in your JavaScript
var cleave = '.input-phone' phone: true phoneRegionCode: '{country}';More examples: the demo page
var Cleave = ;; var cleave = ...For Browserify users, please also run this:
npm install --save babelify browserify-shimAnd add this empty browserify-shim config to your package.json:
"browserify-shim": ;;; ;Then in JSX:
Component { superprops context; thisonCreditCardChange = thisonCreditCardChange; thisonCreditCardFocus = thisonCreditCardFocus; } { // formatted pretty value console; // raw value console; } { // update some state } { return <Cleave placeholder="Enter your credit card number" options=creditCard: true onFocus=thisonCreditCardFocus onChange=thisonCreditCardChange /> ; }As you can see, here you simply use <Cleave/> as a normal <input/> field
<input/> attributesoptions proponChange event listenerUsage for Webpack, Browserify and more in documentation: ReactJS component usage
First include the directive module:
And in your model:
angular ;Then easily you can apply cleave directive to input field:
More usage in documentation: Angular directive usage
npm installBuild assets
gulp buildRun tests
gulp testLint
gulp eslintPublish (build, tests & lint)
gulp publishFor contributors, please run
gulp publishto ensure your PR passes tests and lint, also we have a not in the plan list you may concern.
Cleave.js is licensed under the Apache License Version 2.0