Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

04 Custom Async Validator

In this example we are going to create an async custom validator with Fonk.

Play with demo:

Formik and Fonk 04-custom-async-validator example

Steps to build it

  • Install project dependencies
npm install

Implementing custom synchronous validations is great, but what about asynchronous ones? Let's chek how to do this by coding an example:

  • In this case once the user has entered a valid IBAN, we want to check against the server if that IBAN number belongs to a blacklist, we have the following fake simulation of a rest api call already implemented:


const mockIBANBlackList = ['BE71 0961 2345 6769'];

export const isIBANInBlackList = iban =>
  • We can write our own custom validator:


import { isIBANInBlackList } from '../api';

export const ibanBlackList = ({ value }) =>
  isIBANInBlackList(value).then(isInBlackList => ({
    type: 'IBAN_BLACK_LIST',
    succeeded: !isInBlackList,
    message: isInBlackList ? 'This IBAN is not allowed' : '',
  • Update barrel file:


export * from './country-black-list.validator';
+ export * from './iban-black-list.validator';
  • And add it to our schema:


import { Validators } from '@lemoncode/fonk';
import { createFormikValidation  } from '@lemoncode/fonk-formik';
import { iban } from '@lemoncode/fonk-iban-validator';
import { rangeNumber } from '@lemoncode/fonk-range-number-validator';
+ import { ibanBlackList } from './custom-validators';

export const validationSchema = {
  field: {
    account: [
+     ibanBlackList,

About Basefactor + Lemoncode

We are an innovating team of Javascript experts, passionate about turning your ideas into robust products.

Basefactor, consultancy by Lemoncode provides consultancy and coaching services.

Lemoncode provides training services.

For the LATAM/Spanish audience we are running an Online Front End Master degree, more info:

You can’t perform that action at this time.