---
title: "Magento 2 Add Custom Validation Checkout"
url: "https://dolphinwebsolution.com/magento-2-add-custom-validation-checkout"
date: "2021-04-01T06:23:23+05:30"
modified: "2023-08-24T09:42:45+05:30"
author:
  name: "Mahesh Makwana"
categories:
  - "Magento"
word_count: 200
reading_time: "1 min read"
summary: "We learn how to add custom validation in checkout Magento 2 Sometimes we need to use custom validation into checkout page. Magento provide many default validation. Here given some step to create cu..."
description: "We learn how to add custom validation checkout in Magento 2. Sometimes we need to use custom validation into checkout page."
keywords: "Add Custom Validation Checkout,Magento 2 Add Custom Validation Checkout,Add Custom Validation Checkout in Magento 2,custom validation checkout magento 2, Magento"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Perform CRUD Operation with a custom module in Magento 2"
    url: "https://dolphinwebsolution.com/how-to-perform-crud-operation-with-a-custom-module-in-magento-2"
  - title: "How To Setup Cron Time In Magento 2 System Configuration"
    url: "https://dolphinwebsolution.com/how-to-setup-cron-time-in-magento-2-system-configuration"
  - title: "How To Programmatically Assign Products To Multiple Categories In Magento 2"
    url: "https://dolphinwebsolution.com/how-to-programmatically-assign-products-to-multiple-categories-in-magento-2"
---

# Magento 2 Add Custom Validation Checkout

_Published: April 1, 2021_  
_Author: Mahesh Makwana_  

![](https://dolphinwebsolution.com/wp-content/uploads/2023/02/checkout-1024x512.jpg)

> We learn how to add custom validation in checkout Magento 2 Sometimes we need to use custom validation into checkout page. Magento provide many default validation. Here given some step to create custom validation into checkout magento 2

### We learn how to add custom validation checkout in Magento 2

Sometimes we need to use custom validation on checkout page. [Magento provide many default validation.](https://dolphinwebsolution.com/add-validation-into-custom-form-magento-2 "Magento 2 Default Validations") Here given some steps to create custom validation into checkout Magento 2:

- **Step-1:** Create **requirejs-config.js** at **app/code/Dolphin/CustomValidation/view/frontend**

```
var config = {
    config: {
        mixins: {
            'Magento_Ui/js/lib/validation/validator': {
                'Dolphin_CustomValidation/js/test-mixin': true
            }
        }
    }
}
```

> [Magento 2 Fast checkout extension](https://dolphinwebsolution.com/shop/quick-order-for-magento.html)

- **Step-2:** Create **test-mixin.js** at **app/code/Dolphin/CustomValidation/view/frontend/web/js**

```
define(
    ['jquery'],
   function($) {
  "use strict";
    return function(validator) {
        validator.addRule(
            'validate-five-words',
                function(value, element) {
                    // add you logic here
                    //return value.split(' ').length == 5;
                },
            $.mage.__('If any Error then put here the Message')
        );
        return validator;
    }
});
```

- **Step-3:** You can used this validation using layout **checkout\_index\_index.xml**.

```
<item name="validation" xsi:type="array">
    <item name="required-entry" xsi:type="boolean">true</item>
    <item name="validate-five-words" xsi:type="boolean">true</item>
</item>
```

Now you can check your [checkout](https://docs.magento.com/user-guide/sales/checkout-process.html) page form where you put above validation field. Now successfully apply our custom validation.

I hope this helps you. For any doubts regarding this topic, please write your doubts in the comments section.


---

_View the original post at: [https://dolphinwebsolution.com/magento-2-add-custom-validation-checkout](https://dolphinwebsolution.com/magento-2-add-custom-validation-checkout)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-26 07:37:45 UTC_  
