react-native-credit-card-input is a free, open source e-commerce platforms project written in TypeScript and released under MIT. It has 1,507 GitHub stars, 710 forks and 6 open issues, and was last pushed 10 months ago. On this registry it ranks #29 of 30 tracked projects in E-commerce Platforms, with 5 head-to-head comparisons available.

What is react-native-credit-card-input?

What it is

react-native-credit-card-input is a TypeScript component library for React Native that provides a credit-card input form for Android, iOS, and Web. It lives in the React Native ecosystem and is distributed under the MIT license.

The project solves the problem of building a card entry form without writing each field, validation rule, formatting behavior, and navigation flow from scratch. It gives developers a form that accepts card number, expiry, and CVC values, recognizes common card brands, and returns sanitized state to an application handler.

Key capabilities

  • The package exports CreditCardInput and LiteCreditCardInput components, plus CardView, for different visual presentations of a credit-card form.
  • The full component uses a skeuomorphic card appearance, while the Lite variant provides a compact layout for smaller screens.
  • The form validates and formats input while the user types, and onChange returns sanitized values such as number, expiry, cvc, and detected type.
  • Returned state includes a valid flag and per-field status values of incomplete, invalid, or valid, which can control form submission.
  • Card type detection covers visa, master-card, american-express, diners-club, discover, jcb, unionpay, and maestro, with null when no type is recognized.
  • The form is navigatable using the keypad, and LiteCreditCardInput animations require LayoutAnimation to be enabled on Android.

Who uses it and how

  • React Native developers can add the component to an Android, iOS, or Web payment flow and use onChange to decide when the submit action should be enabled.
  • Teams building proof-of-concept checkout screens can use the provided example and Expo Snack to evaluate the component before integrating it into a larger application.
  • Developers who need a compact card form can use LiteCreditCardInput, while those who want a more visual card presentation can use CreditCardInput.

Getting started

Install the package with yarn add react-native-credit-card-input, then import CreditCardInput or LiteCreditCardInput into React Native code. The repository also provides a local example that can be run with yarn install and yarn example ios, yarn example android, or yarn example web.

When to use it โ€” and when not to

Use the package when a React Native app needs a quick credit-card input component or proof-of-concept payment form and the supplied UI fits the product. Avoid it when the project requires a deeply customized form system, because the README recommends using a form library such as react-hook-form together with card-validator in that case. The component handles input presentation and validation state, but it does not provide payment processing, storage, backend infrastructure, or hosted deployment details.

project readme (upstream, from github) โ€” read inline

React Native Credit Card Input - Finally updated in 2024!

Example on Expo Snack - Easy (and good looking) credit-card input for your React Native Project ๐Ÿ’ณ ๐Ÿ’ณ

Code:

<CreditCardInput />
// or
<LiteCreditCardInput />

Features

  • Skeuomorphic credit-card ๐Ÿ’ณ
  • Lite version for smaller screens / compact layout
  • Credit-card input validations & formatting while you're typing
  • Form is fully navigatable using keypad
  • Works on both Android, iOS and Web!

Usage

yarn add react-native-credit-card-input

then add these lines in your react-native codebase

import { CreditCardInput, LiteCreditCardInput } from "react-native-credit-card-input";

<CreditCardInput onChange={_onChange} />
// or
<LiteCreditCardInput onChange={_onChange} />

// Note: You'll need to enable LayoutAnimation on android to see LiteCreditCardInput's animations
// UIManager.setLayoutAnimationEnabledExperimental(true);

And then on your onChange handler:

_onChange => form => console.log(form);

// will print:
{
  valid: true, // will be true once all fields are "valid" (time to enable the submit button)
  values: { // will be in the sanitized and formatted form
  	number: "4242 4242",
  	expiry: "06/19",
  	cvc: "300",
  	type: "visa", // will be one of [null, "visa", "master-card", "american-express", "diners-club", "discover", "jcb", "unionpay", "maestro"]
  },
  status: {  // will be one of ["incomplete", "invalid", and "valid"]
	number: "incomplete",
	expiry: "incomplete",
	cvc: "incomplete",
  },
};

Example

Expo Snack

Or run it locally

yarn install

yarn example ios
# or
yarn example android
# or
yarn example web

Should I used this in my project?

  • Yes, if you need a quick credit card input component for your project or proof of concept.
  • Yes, if the current UI/component fit your use case
  • Otherwise, you're probably better off using your favorite form library and implementing the validation with the card-validator package!

Components

LiteCreditCardInput

Prop Type Description
autoFocus boolean Optional. Specifies if the input should auto-focus.
style ViewStyle Optional. Custom style for the component's container.
inputStyle TextStyle Optional. Custom style for the input fields.
placeholderColor string Optional. Color for the placeholder text.
placeholders { number: string; expiry: string; cvc: string; } Optional. Custom placeholders for the input fields.
onChange (formData: CreditCardFormData) => void Required. Callback function called when form data changes.
onFocusField (field: CreditCardFormField) => void Optional. Callback function called when a field gains focus.

CreditCardInput

Prop Type Description
autoFocus boolean Optional. Specifies if the input should auto-focus.
style ViewStyle Optional. Custom style for the component's container.
labelStyle TextStyle Optional. Custom style for the labels.
inputStyle TextStyle Optional. Custom style for the input fields.
placeholderColor string Optional. Color for the placeholder text.
labels { number: string; expiry: string; cvc: string; } Optional. Custom labels for the input fields.
placeholders { number: string; expiry: string; cvc: string; } Optional. Custom placeholders for the input fields.
onChange (formData: CreditCardFormData) => void Required. Callback function called when form data changes.
onFocusField (field: CreditCardFormField) => void Optional. Callback function called when a field gains focus.

CardView

Prop Type Description
focusedField 'name' | 'number' | 'expiry' | 'cvc' Optional. Specifies which field is currently focused.
type CreditCardIssuer Optional. Specifies the type of the credit card issuer.
name string Optional. The name on the credit card.
number string Optional. The credit card number.
expiry string Optional. The expiry date of the credit card.
cvc string Optional. The CVC code of the credit card.
placeholders { number: string; expiry: string; cvc: string; name: string; } Optional. Custom placeholders for the input fields.
style ViewStyle Optional. Custom style for the component's container.
fontFamily string Optional. Custom font family for the text.
imageFront ImageSourcePropType Optional. Image source for the front of the credit card.
imageBack ImageSourcePropType Optional. Image source for the back of the credit card.

Frequently asked questions

Is react-native-credit-card-input free to use?

react-native-credit-card-input is open source under the MIT licence. There is no licence fee and no seat count โ€” you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does react-native-credit-card-input do?

Easy, cross-platform credit-card input for your React Native Project! Start accepting payment ๐Ÿ’ฐ in your app today!

What is react-native-credit-card-input written in?

react-native-credit-card-input is primarily written in TypeScript. Its source is publicly available at https://github.com/sbycrosz/react-native-credit-card-input, and it has 1,507 GitHub stars.