We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

    By performing below steps one-by-one, we can put any validation in the checkout billing address.
    In this example, we are going to set validation for the telephone field.

    Here validation will be about the maximum and minimum length of telephone Exact ten digits going to get allowed.

    First, you have to create a file in your existing module following to below path,

    appcode[VendorName][ModuleName]etcfrontenddi.xml
    <type name="MagentoCheckoutBlockCheckoutLayoutProcessor">
        <plugin disabled="false" name="checkout_billing_address_layoutProcessor" sortOrder="110" type="[VendorName][ModuleName]PluginBlockCheckoutLayoutProcessor"/>
    </type>

    Then, you have to create another file at a given path,

    appcode[VendorName][ModuleName]PluginBlockCheckoutLayoutProcessor.php
    <?php
    
    namespace [VendorName][ModuleName]PluginBlockCheckout;
    
    class LayoutProcessor {
    
        public function afterProcess(MagentoCheckoutBlockCheckoutLayoutProcessor $subject, array $jsLayout) {
            if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
                            ['payment']['children']['payments-list']['children']
                    )) {
    
                foreach ($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
                ['payment']['children']['payments-list']['children'] as $key => $payment) {
    
                    /* Telephone Billing Address */
                    if (isset($payment['children']['form-fields']['children']['telephone'])) {
                        $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
                                ['payment']['children']['payments-list']['children'][$key]['children']['form-fields']['children']
                    ['telephone']['validation'] = ['required-entry' => true, 'min_text_length' => 10, 'max_text_length' => 10];
                    }
                }
            }
    
            return $jsLayout;
        }
    
    }

    After doing the above steps you need to run below command:

    php bin/magento cache:flush
    php bin/magento cache:clean

    You can also put validations for other fields. All that you need to do is to change the field name in the form-field section. You can also change default validation error message using .csv in your module.

    field_5bfb909c5ccae

      Get a Free Quote