---
title: "How to Add Custom Validation to Address Field in Checkout in Magento 2?"
url: "https://magecomp.com/blog/add-custom-validation-to-address-field-in-checkout-in-magento-2/"
date: "2019-12-13T17:52:32+00:00"
modified: "2025-02-21T08:50:11+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 573
reading_time: "3 min read"
summary: "Hello, folks"
description: "In this article, We have covered full code guidelines for how to add the custom validation to the address field of the checkout page in Magento 2."
keywords: "custom, validation, addressfield, checkout, magento2, How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "Magento 2 Store Management Made Easy with Admin Action Login Extension"
    url: "https://magecomp.com/blog/magento-2-admin-action-login-extension-integration-and-guide/"
  - title: "Magento 2: How to Add Custom Text after Billing Address and Shipping Address in Admin Order View Page?"
    url: "https://magecomp.com/blog/magento-2-add-custom-text-after-billing-address-and-shipping-address-in-admin-order-view-page/"
  - title: "Magento 2: How to Add Section after Image Gallery at Product Detail Page"
    url: "https://magecomp.com/blog/magento-2-add-section-after-image-gallery-at-product-detail-page/"
---

# How to Add Custom Validation to Address Field in Checkout in Magento 2?

_Published: December 13, 2019_  
_Author: Dhiren Vasoya_  

![How to Add Custom Validation to Address Field in Checkout in Magento 2](https://magecomp.com/blog/wp-content/uploads/2019/12/How-to-Add-Custom-Validation-to-Address-Field-in-Checkout-in-Magento-2-1024x512.webp)

Hello, folks

I hope you are all doing great. I am back with another great article on **how you can add custom validation to the address field of the checkout page in Magento 2**.

[![Hire Magento Programmer](https://magecomp.com/blog/wp-content/uploads/2025/02/Hire-Magento-Programmer-CTA-4.webp)](https://magecomp.com/services/hire-magento-programmer/)

Sometimes you want to have an extension or a code that can be integrated with your Magento 2 store that can add the custom validation to address field of the checkout page. So, the user will only be allowed to proceed once all the custom validation rules are satisfied.

The good news is that you can do that with the help of your coding knowledge. And even if you don’t know anything about coding, you can just [**Contact**](https://magecomp.com/support/) our Magento 2 Certified Developers.

Below are the steps and codes you need to follow and apply in your Magento 2 store to add custom validation to the address field in the checkout.

1. Create a file at a given Path,

**app\code\Vendor\Extension\etc\frontend\di.xml**

Once the file is created then use the below code to create the custom validation,

```
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
   <type name="MagentoCheckoutBlockCheckoutLayoutProcessor">
      <plugin name="custom-validation-street-address" type="VendorExtensionModelCheckoutLayoutprocessorplugin"/>
   </type>
</config>
```

Follow the above step for every vendor if your store supports multivendor functionality.

2. Create another file at a given path,

**app\code\Vendor\Extension\Model\Checkout\Layoutprocessorplugin.php**

Once the file is created then use the below code to apply the custom validation,

```
<?php
namespace VendorExtensionModelCheckout;
class Layoutprocessorplugin
{
    public function afterProcess(
        MagentoCheckoutBlockCheckoutLayoutProcessor $subject,
        array  $jsLayout
    ) {
        $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
        ['billingAddress']['children']['shipping-address-fieldset']['children']['street'] = [
            'component' => 'Magento_Ui/js/form/components/group',
            'label' => __('Street Address'),
            'required' => true,
            'dataScope' => 'billingAddress.street',
            'provider' => 'checkoutProvider',
            'sortOrder' => 10,
            'type' => 'group',
            'additionalClasses' => 'street',
            'children' => [
                [
                    'component' => 'Magento_Ui/js/form/element/abstract',
                    'config' => [
                        'customScope' => 'billingAddress',
                        'template' => 'ui/form/field',
                        'elementTmpl' => 'ui/form/element/input'
                    ],
                    'dataScope' => '0',
                    'provider' => 'checkoutProvider',
                    'validation' => ['required-entry validate-alphanum-with-spaces' => true, "min_text_length" => 5, "max_text_length" => 255],
                ],
                [
                    'component' => 'Magento_Ui/js/form/element/abstract',
                    'config' => [
                        'customScope' => 'shippingAddress',
                        'template' => 'ui/form/field',
                        'elementTmpl' => 'ui/form/element/input'
                    ],
                    'dataScope' => '1',
                    'provider' => 'checkoutProvider',
                    'validation' => ['required-entry validate-alphanum-with-spaces' => true, "min_text_length" => 5, "max_text_length" => 255],
                ]
            ]
        ];
        return $jsLayout;
    }
}
```

[![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-3.webp)](https://magecomp.com/services/magento-upgrade-services/)

Once the code is applied, clear the cache and refresh it. The custom validation will now start to work. So today, we learned that how you can add custom validation to address field in checkout for Magento 2 Platform. Using the codes described here, you will be able to set the custom validation to address field in the checkout. Also, install [Custom Checkout Fields](https://magecomp.com/magento-2-custom-checkout-fields.html) which helps the store admin customize the checkout page by adding extra fields. If anything goes wrong or you don’t know anything about coding for Magento, then you can always contact our **Magento certified team** of expert developers. Just visit our [support page](https://magecomp.com/support/) or [hire a developer](https://magecomp.com/hire-magento-developer.html) for your store.

Lastly, if you found this helpful, then give it a thumbs-up and share it with your Magento friends and colleagues. Do let us know if you had any problem while implementing the code by commenting below.

[![Magento Malware Removal](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-Malware-Removal-CTA-4.webp)](https://magecomp.com/magento-malware-removal.html)

Happy coding! ?


---

_View the original post at: [https://magecomp.com/blog/add-custom-validation-to-address-field-in-checkout-in-magento-2/](https://magecomp.com/blog/add-custom-validation-to-address-field-in-checkout-in-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-10-22 10:26:34 UTC_  
