ViraStack
  • About
  • Support
HomeGet StartedExamples
ViraStack

A DX-first toolkit for frontend developers: starters, agent rules, form hooks, and a guide.

Products

  • ViraStack Start
  • ViraStack AI
  • ViraStack Mask
  • ViraStack Password
  • ViraStack Guide

Explore

  • About
  • Brand
  • Support

© 2026 ViraStack.

Open source · MIT

Examples

  • All
  • Alpha
  • Card
  • Credit card form
  • Currency
  • CVV
  • Date
  • Email
  • Expiry
  • IBAN
  • Numeric
  • Password
  • Phone
  • Tax number (VKN)
  • TCKN
  • Text
  • URL
  • Username
  • ZIP code

Credit card form

Card number, expiry, and CVV together. CVV automatically expands to 4 digits for Amex.

← All examples

Preview

rawValue: -

value: -

rawValue: -

value: -

rawValue: -

value: -

import { useForm } from "react-hook-form"
import { useViraMask } from "@virastack/mask"
 
function CreditCardForm() {
  const form = useForm({
    defaultValues: { card: "", expiry: "", cvv: "" },
  })
 
  const { card, expiry, cvv } = useViraMask({
    form,
    schema: {
      card: { preset: "card", errorMessage: "Invalid card number" },
      expiry: { preset: "expiry", errorMessage: "Invalid or past date" },
      cvv: "cvv",
    },
  })
 
  return (
    <>
      <input {...card} placeholder="0000 0000 0000 0000" />
      <input {...expiry} placeholder="12/28" />
      <input {...cvv} placeholder="123" />
    </>
  )
}

Details

  • Use card + expiry + cvv in the same schema.
  • American Express cards start with 34 or 37. In that case the card number switches to a 4-6-5 grouped mask and the CVV field automatically expands from 3 to 4 digits (resolveMask).
  • The card field has validator: 'luhn'; expiry has validator: 'expiry' built in.

See useViraMask() for the hook API and custom mask for custom masks.

PreviousCardNextCurrency

On this page

  • Preview
  • Details
Something wrong? Fix it