Skip to content

add or edit address validation

I am trying to add validation to address fields. I have successfully achieved my requirement in checkout_index_index.xml for shipping address. same thing i want to have validation for add or edit address book.

I have used following code for checkout_index_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="checkout" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
            <referenceBlock  name="checkout.root">
                <arguments>
                    <argument name="jsLayout" xsi:type="array">
                        <item name="components" xsi:type="array">
                            <item name="checkout" xsi:type="array">
                                <item name="children" xsi:type="array">
                                    <item name="steps" xsi:type="array">
                                        <item name="children" xsi:type="array">
                                            <item name="shipping-step" xsi:type="array">
                                                <item name="children" xsi:type="array">
                                                    <item name="shippingAddress" xsi:type="array">
                                                        <item name="children" xsi:type="array">
                                                            <item name="shipping-address-fieldset" xsi:type="array">
                                                                <item name="children" xsi:type="array">
                                                                    <item name="firstname" xsi:type="array">
                                                                        <item name="validation" xsi:type="array">
                                                                            <item name="validate-alphanum-with-spaces" xsi:type="boolean">true</item>
                                                                        </item>
                                                                    </item>
                                                                    <item name="lastname" xsi:type="array">
                                                                        <item name="validation" xsi:type="array">
                                                                            <item name="validate-alphanum-with-spaces" xsi:type="boolean">true</item>
                                                                        </item>
                                                                    </item>
                                                                    <item name="company" xsi:type="array">
                                                                        <item name="validation" xsi:type="array">
                                                                            <item name="validate-alphanum-with-spaces" xsi:type="boolean">true</item>
                                                                        </item>
                                                                    </item>                                                            
                                                                    <item name="city" xsi:type="array">
                                                                        <item name="validation" xsi:type="array">
                                                                            <item name="validate-alphanum-with-spaces" xsi:type="boolean">true</item>
                                                                        </item>
                                                                    </item>
                                                                    <item name="country_id" xsi:type="array">
                                                                        <item name="validation" xsi:type="array">
                                                                            <item name="numeric" xsi:type="boolean">true</item>
                                                                        </item>
                                                                    </item>
                                                                    <item name="region_id" xsi:type="array">
                                                                        <item name="validation" xsi:type="array">
                                                                            <item name="numeric" xsi:type="boolean">true</item>
                                                                        </item>
                                                                    </item>
                                                                    <item name="postcode" xsi:type="array">
                                                                        <item name="validation" xsi:type="array">
                                                                            <item name="validate-alphanum-with-spaces" xsi:type="boolean">true</item>
                                                                        </item>
                                                                    </item>
                                                                    <item name="telephone" xsi:type="array">
                                                                        <item name="validation" xsi:type="array">
                                                                            <item name="numeric" xsi:type="boolean">true</item>
                                                                        </item>
                                                                    </item>
                                                                </item>
                                                            </item>
                                                        </item>
                                                    </item>
                                                </item>
                                            </item>
                                        </item>
                                    </item>
                                </item>
                            </item>
                        </item>
                    </argument>
                </arguments>
            </referenceBlock>
    </body>
</page>

I have gone through this question but I din’t get how to do so.

Please guide me to achive the same.