Card number
Learn how to customise the card number component.
Styling
const cardNumberConfig: CardNumberComponentConfig = {
formatCardNumber: boolean,
renderCardBrandSelector: boolean,
acceptedCardBrands: [],
validationOnChange: boolean,
validationOnBlur: boolean,
showHintIcon: boolean,
showTooltip: boolean,
hintIconSrc: string,
cardCvcComponent: CardCvcComponent,
cardBrandSelectorComponent: CardBrandSelectorComponent,
dynamicCardImageComponent: DynamicCardImageComponent,
inputAttributes: InputAttributes,
required: boolean,
placeholder: string,
componentStyles: {
base: CSSProperties,
valid: CSSProperties,
invalid: CSSProperties,
input: CSSProperties
},
inputStyles: {
base: CSSProperties,
valid: CSSProperties,
invalid: CSSProperties
},
label: string,
labelStyles: {
base: CSSProperties,
valid: CSSProperties,
invalid: CSSProperties
},
labelPosition: string,
invalidTextStyles: CSSProperties,
invalidTextPosition: string,
guideText: string,
validations: {},
invalidIconSrc: string,
validIconSrc: string,
displayValidIcon: boolean,
displayInvalidIcon: boolean,
tooltipAriaLabel: string,
ariaLabel: string,
displayRequiredIcon: boolean,
allowToCopyPaste: boolean,
validationOnBlur: boolean,
validationOnChange: boolean,
tabIndex: number
};
Property | Description |
---|---|
| Whether to auto-format the number as typed. |
| Whether to rend the card brand drop-down. |
| The list of accepted card brands. |
| Whether to validate on input change. |
| Whether to validate on input blur. |
| Whether to display a hint icon. |
| The URL to your custom hint icon. |
| Whether to show a tooltip when hovering over the hint. |
| Configuration for the CVC component. See Card CVC. |
| Configuration for the card brand selector component. See Card brand selector. |
| Component to display dynamic card images. See Dynamic card image. |
| Additional HTML input attributes. |
| Whether the field is required for submission. |
| The placeholder text to display when the field is empty. |
| Custom styling for the component. |
| Base styling for the component. |
| Styling for the component when it's valid. |
| Styling for the component when it's not valid. |
| Styling for the input element. |
| Style for input field in various states. |
| The input label's text. |
| The label styling, based on the state. |
| The position of the label, relative to the input field.
|
| Style for validation message text. |
| The position of the invalid text message, relative to the input field.
|
| The helper text to display below the input field. |
| Validation rules to be applied to the input field. |
| The URL for the icon shown on invalid input. |
| The URL for the icon shown on valid input. |
| Whether to display a success icon. Defaults to |
| Whether to display an error icon. Defaults to |
| The aria label for the tooltip. |
| The aria label for the field component. |
| Whether to display a required icon. Defaults to |
| Whether to allow copy/paste in the input fields. |
| Whether to run validation when input loses focus. |
| Whether to run validation as a value changes. |
| The tab index of the input element. |
Callbacks
const cardCvcConfig: CardCvcComponentConfig = {
onChange: (event: InputEvent) => void,
onFocus: (event: FocusEvent) => void,
onBlur: (event: FocusEvent) => void,
onValidationPassed: (data: ValidationResult[]) => void,
onValidationFailed: (data: ValidationResult[]) => void,
onCardBrandDetected?: (event: Event) => void,
onCardBrandCannotRecognised?: (event: Event) => void
};
Callback | Description |
---|---|
onChange: (event: InputEvent) => void | Event handler for when the input value changes. |
onFocus: (event: FocusEvent) => void | Event handler for when the input receives focus. |
onBlur: (event: FocusEvent) => void | Event handler for when the input loses focus. |
onValidationPassed: (data: ValidationResult[]) => void | Event handler for when all validations pass. |
onValidationFailed: (data: ValidationResult[]) => void | Event handler for when any validation fails. |
onCardBrandDetected: (event: Event) => void | Event handler for when a card brand is detected. |
onCardBrandCannotRecognised: (event: Event) => void | Event handler for when a card brand can't be recognised. |
For more information about callbacks, see Events.
Example
const cardNumberConfig: CardNumberComponentConfig = {
label: "Card number",
placeholder: "1234 5678 9012 3456",
required: true,
formatCardNumber: true,
renderCardBrandSelector: true,
showHintIcon: true,
showTooltip: true,
validationOnChange: true,
validationOnBlur: true,
acceptedCardBrands: ["Visa", "MasterCard", "Amex"],
inputStyles: {
base: {
border: "1px solid #ccc",
padding: "12px",
borderRadius: "4px",
fontSize: "16px"
},
valid: {
borderColor: "#28a745"
},
invalid: {
borderColor: "#dc3545"
}
},
labelStyles: {
base: {
fontWeight: "500",
marginBottom: "8px"
}
},
tabIndex: 1,
onChange: (event) => {
console.log("Card number changed:", event.target.value);
},
onFocus: (event) => {
console.log("Card number focused");
},
onBlur: (event) => {
console.log("Card number blurred");
},
onValidationPassed: (data) => {
console.log("Card number valid");
},
onValidationFailed: (data) => {
console.log("Card number validation failed:", data);
},
onCardBrandDetected: (event) => {
console.log("Card brand detected:", event);
},
onCardBrandCannotRecognised: (event) => {
console.log("Card brand not recognised:", event);
}
};
Updated 3 days ago