Credit/Debit Card validator for Adonisjs

Usage no npm install needed!

<script type="module">
  import shagitalAdonisjsCardValidator from 'https://cdn.skypack.dev/@shagital/adonisjs-card-validator';


Adonisjs Card Validator ▲

npm npm (scoped) NPM


Adds credit/debit card validation functionality to Adonisjs using Luhn algorithm

Step One - Install

Via Adonis CLI

adonis install @shagital/adonisjs-card-validator

Via npm/yarn

  • Install package
// via npm
npm require @shagital/adonisjs-card-validator

// via yarn
yarn add @shagital/adonisjs-card-validator

Step Two - Register Provider

Open start/app.js and add @shagital/adonisjs-card-validator/providers/CreditCardValidationProvider to the providers array


You use the card, cvv and cardExp validation syntax just like you'd normally do validation in Adonisjs. Examples below: NOTE: The specified card type need to be supported. Currency supported card types are:

  • visaelectron
  • maestro
  • forbrugsforeningen
  • dankort
  • visa
  • mastercard
  • amex
  • dinersclub
  • discover
  • unionpay
  • jcb

controller method


const { validate } = use('Validator')

class UserController {

  async store ({ request, session, response }) {
    const rules = {
      card: 'required|card', // validate card number
      cvv: 'required|cvv', // validate cvv2
      expiry_date: 'required|cardExp', // validate card expiry date in the format YYYY-MM

    const validation = await validate(request.all(), rules)

    if (validation.fails()) {
      return response.redirect('back')

    return 'Validation passed'



'use strict'

class StoreUser {
  get rules () {
    return {
       card: 'required|card:mastercard', // validate mastercard card number
       cvv: 'required|cvv:mastercard', // validate mastercard cvv2
       expiry_date: 'required|cardExp', // validate card expiry date in the format YYYY-MM


Free for all, if you find an issue with the package or think of an improvement, please send in a PR.