Skip to main content

Elements Components

CardNumberElement

The CardNumberElement component features a card number input, by wrapping the React Native TextInput component, which makes its interface similar to working directly with a regular TextInput.

import React, { useRef } from 'react';
import {
SafeAreaView,
ScrollView,
StatusBar,
StyleSheet,
View,
} from 'react-native';
import {
BTRef,
CardNumberElement,
} from '@basis-theory/basis-theory-react-native';

const App = () => {
const ref = useRef<BTRef>(null);

return (
<SafeAreaView>
<StatusBar />
<ScrollView contentInsetAdjustmentBehavior="automatic">
<View style={styles.viewContainer}>
<CardNumberElement
btRef={ref}
placeholder="Card Number"
style={styles.cardNumber}
/>
</View>
</ScrollView>
</SafeAreaView>
);
};

const styles = StyleSheet.create({
cardNumber: {
backgroundColor: '#eeeeee',
borderColor: 'blue',
borderWidth: 2,
color: 'purple',
height: 40,
margin: 12,
padding: 10,
},
viewContainer: {
display: 'flex',
flexDirection: 'column',
marginTop: 32,
},
});

export default App;

Properties

PropertyRequiredTypeDescription
btReffalseobject/functionCallback ref function to store/receive the Element instance. Review the using refs section for more information
stylefalseobjectReactNative styles used to customize the Element appearance
editablefalsebooleanBoolean used to set the editable attribute of the Element
placeholderfalsestringString used to customize the placeholder attribute of the Element

Methods

The methods available to CardNumberElement can be accessed through the refs. Review the using refs section for more information.

Masking

Element masks enable user input to be restricted and formatted to meet a pre-defined format. The CardNumberElement automatically sets a mask based on the card brand.

Card Brands

The first several digits of the card number are analyzed as the user is typing to determine the card brand. The brand is used to automatically set a mask to a brand-specific format.

Supported card brands are defined in the table below:

BrandIdentifierCard Number DigitsCVC Digits
American ExpressamericanExpress154
Diners ClubdinersClub14, 16, 193
Discoverdiscover16, 193
Eloelo163
Hiperhiper163
HiperCardhipercard163
JCBjcb16-193
Maestromaestro12-193
Mastercardmastercard163
MIRmir16-193
UnionPayunionPay14-193
Visavisa16, 18, 193
Some card brands have issued card numbers with multiple lengths. The Card Number Digits column documents all acceptable card number lengths for the brand (in number of digits, excluding formatting characters).

CardExpirationDateElement

The CardExpirationDateElement component features a card number input, by wrapping the React Native TextInput component, which makes its interface similar to working directly with a regular TextInput.

import React, { useRef } from 'react';
import {
SafeAreaView,
ScrollView,
StatusBar,
StyleSheet,
View,
} from 'react-native';
import {
BTRef,
CardExpirationDateElement,
} from '@basis-theory/basis-theory-react-native';

const App = () => {
const ref = useRef<BTRef>(null);

return (
<SafeAreaView>
<StatusBar />
<ScrollView contentInsetAdjustmentBehavior="automatic">
<View style={styles.viewContainer}>
<CardExpirationDateElement
btRef={ref}
placeholder="Card Expiration Date"
style={styles.cardExpiration}
/>
</View>
</ScrollView>
</SafeAreaView>
);
};

const styles = StyleSheet.create({
cardExpiration: {
backgroundColor: '#eeeeee',
borderColor: 'blue',
borderWidth: 2,
color: 'purple',
height: 40,
margin: 12,
padding: 10,
},
viewContainer: {
display: 'flex',
flexDirection: 'column',
marginTop: 32,
},
});

export default App;

Properties

PropertyRequiredTypeDescription
btReffalseobject/functionCallback ref function to store/receive the Element instance. Review the using refs section for more information
stylefalseobjectReactNative styles used to customize the Element appearance
editablefalsebooleanBoolean used to set the editable attribute of the Element
placeholderfalsestringString used to customize the placeholder attribute of the Element

Methods

The methods available to CardExpirationDateElement can be accessed through the refs. Review the using refs section for more information.

Masking

Element masks enable user input to be restricted and formatted to meet a pre-defined format. The CardExpirationDateElement automatically sets a mask of MM/YY.

CardVerificationCodeElement

The CardVerificationCodeElement component features a card number input, by wrapping the React Native TextInput component, which makes its interface similar to working directly with a regular TextInput.

import React, { useRef } from 'react';
import {
SafeAreaView,
ScrollView,
StatusBar,
StyleSheet,
View,
} from 'react-native';
import {
BTRef,
CardVerificationCodeElement,
} from '@basis-theory/basis-theory-react-native';

const App = () => {
const ref = useRef<BTRef>(null);

return (
<SafeAreaView>
<StatusBar />
<ScrollView contentInsetAdjustmentBehavior="automatic">
<View style={styles.viewContainer}>
<CardVerificationCodeElement
btRef={ref}
placeholder="CVC"
style={styles.cvc}
/>
</View>
</ScrollView>
</SafeAreaView>
);
};

const styles = StyleSheet.create({
cvc: {
backgroundColor: '#eeeeee',
borderColor: 'blue',
borderWidth: 2,
color: 'purple',
height: 40,
margin: 12,
padding: 10,
},
viewContainer: {
display: 'flex',
flexDirection: 'column',
marginTop: 32,
},
});

export default App;

Properties

PropertyRequiredTypeDescription
btReffalseobject/functionCallback ref function to store/receive the Element instance. Review the using refs section for more information
stylefalseobjectReactNative styles used to customize the Element appearance
editablefalsebooleanBoolean used to set the editable attribute of the Element
placeholderfalsestringString used to customize the placeholder attribute of the Element

Methods

The methods available to CardVerificationCodeElement can be accessed through the refs. Review the using refs section for more information.

Masking

Element masks enable user input to be restricted and formatted to meet a pre-defined format. The CardVerificationCodeElement automatically sets a mask of 4 digits.