whatisgithub

What is cleave.js?

nosir/cleave.js — explained in plain English

Analysis updated 2026-06-24

17,875JavaScriptAudience · developerComplexity · 2/5Setup · easy

In one sentence

A small JavaScript library that formats text inside a form input as the user types, automatically inserting spaces, dashes, and slashes to make credit card numbers, phone numbers, and dates easy to read.

Mindmap

mindmap
  root((repo))
    What it formats
      Credit card numbers
      Phone numbers
      Dates
      Custom patterns
    How it works
      Wraps a text input
      Rewrites on keystroke
      Raw value still readable
    Integration options
      Plain script tag
      React component
      AngularJS directive
      ES Module
    Status
      Deprecated by author
      Successor is cleave-zen
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Add automatic credit card formatting with spaces every four digits to a checkout page without writing custom key-event logic.

USE CASE 2

Format a phone number input in real time with country code and dashes so users can see they are entering it correctly as they type.

USE CASE 3

Apply a custom delimiter pattern to an ID or code input so long strings stay scannable without any validation logic on the client side.

What is it built with?

JavaScriptES ModuleCommonJSAMDReactAngularJS

How does it compare?

nosir/cleave.jsjacksontian/fkspinojs/pino
Stars17,87517,94617,803
LanguageJavaScriptJavaScriptJavaScript
Setup difficultyeasyeasyeasy
Complexity2/51/52/5
Audiencedeveloperdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

This project has been deprecated by its author, the README points to the successor library cleave-zen for new projects.

So what is it?

Cleave.js is a small JavaScript helper that formats text inside an input field as the user types. Instead of writing complicated rules to insert spaces, dashes, or slashes into things like credit card numbers, phone numbers, dates, or large numerals, you point Cleave at an input element and tell it what kind of value it is meant to hold. The library then keeps the visible text neatly grouped and readable while the user is still typing, which makes long sequences of digits much less error-prone. It works by wrapping a normal text input. You give it a CSS selector for the field and an options object describing the format, such as credit card mode, phone mode with a country code, or a custom pattern of delimiters, prefixes, and digit blocks. As keystrokes happen, Cleave rewrites the displayed value to match the chosen format, while still letting you read out the raw value when you need to send data to a backend. The README is explicit that Cleave is about readability, not validation, so checks for whether a card or phone number is actually valid still belong on the server. You would reach for it when building forms where typed input is hard to scan, like checkout pages, signup flows, or admin tools that capture identifiers. It ships in several flavors so it can drop into different setups: a plain script tag, CommonJS, AMD, an ES Module build, a ReactJS component, and an AngularJS 1.x directive, with community TypeScript types available separately. The README also notes the project has been deprecated by its author, who points users to a successor project called cleave-zen.

Copy-paste prompts

Prompt 1
Using Cleave.js, add live credit card formatting to this HTML input element so it shows spaces every four digits and still lets me read the raw value on form submit.
Prompt 2
I have a React checkout form. Show me how to use the Cleave.js React component to format a card number, expiry date, and CVV field as the user types.
Prompt 3
I need a phone input for US numbers using Cleave.js. Give me the options object and show me how to retrieve the unformatted digits before sending to the server.

Frequently asked questions

What is cleave.js?

A small JavaScript library that formats text inside a form input as the user types, automatically inserting spaces, dashes, and slashes to make credit card numbers, phone numbers, and dates easy to read.

What language is cleave.js written in?

Mainly JavaScript. The stack also includes JavaScript, ES Module, CommonJS.

How hard is cleave.js to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is cleave.js for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.