I Want To Set Minimum Length Value For Street Address Field On Admin Side

enter image description here

I want to set min_text_length = 5 For Street Address Field In Customer Address Form

I am Trying To Update Attribute but Not Working

public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
        if (version_compare($context->getVersion(), '1.0.1', '<')) {
            $customerSetup = $this->customerSetup->create(['setup' => $setup]);
                    'type' => 'static',
                    'label' => 'Street Address',
                    'input' => 'multiline',
                    'backend' => \Magento\Eav\Model\Entity\Attribute\Backend\DefaultBackend::class,
                    'sort_order' => 70,
                    'multiline_count' => 4,
                    'validate_rules' => '{"max_text_length":255,"min_text_length":5}',
                    'position' => 70,

In Database Already Set {"max_text_length":255,"min_text_length":5} But Validation not Working

enter image description here

Note :- Admin Side Not Frontend Side.

  • you can update attribute and add validation by setup script(can add manually from DB),For front checkout remove validation by changing LayoutProcessor.php and do same thing in register and update address section by removing validation class – Ketan Borada Jun 19 '19 at 6:56
  • i know about address form and checkout page but in admin side not find any reference or solution – Rk Rathod Jun 19 '19 at 7:00
  • What is your magento version? – Sohel Rana Jun 19 '19 at 7:03
  • v 2.2.8 @Sohel Rana – Rk Rathod Jun 19 '19 at 7:03
  • Please post your code/ mention clearly which form you want to customize in question. – Vivek Kumar Jun 19 '19 at 7:11

You Can do it by Script and update validation within it.You have to change

'validate_rules' => '{"max_text_length":255,"min_text_length":5}',

You can change it directly from DB you have to do it carefully.

  • Open table eav_attribute and find attribute_code street and get attribute_id from it (generally attribute_id is 28).

enter image description here

  • Open table customer_eav_attribute and find that attribute_id (28 in my case). update in validate_rules column {"max_text_length":255,"min_text_length":5}

enter image description here

  • Now it is done in admin

    enter image description here

Note: You have to remove if it occurs in front

|improve this answer|||||
  • let me check and replay soon – Rk Rathod Jun 19 '19 at 7:35
  • no bro its not working i have already try to update attribute – Rk Rathod Jun 19 '19 at 7:40
  • but in data base already set {"max_text_length":255,"min_text_length":5} but validation is not working – Rk Rathod Jun 19 '19 at 7:40
  • 1+ for response – Rk Rathod Jun 19 '19 at 7:49
  • may any other extension conflicts or js error,otherwise you can check it working for me – Ketan Borada Jun 19 '19 at 8:39

i am not sure if this works

<rule name="required-entry" xsi:type="boolean">true</rule>

Example from first name

<field name="city" formElement="input">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="source" xsi:type="string">address</item>

remove this validation

                <rule name="required-entry" xsi:type="boolean">true</rule>

up to here

|improve this answer|||||
  • its not working – Rk Rathod Jun 17 '19 at 5:56
  • @RkRathod hi sorry i thought you wanted to remove the validation. i will let you know if i find something. sorry again – jibin george Jun 17 '19 at 7:25
  • @RkRathod try this : <item name="max_text_length" xsi:type="number">5</item> – jibin george Jun 17 '19 at 7:34
  • @RkRathod did it work? or was it something new you found – jibin george Jun 17 '19 at 8:05
  • @RkRathod if you dont mind will you share the answer? – jibin george Jun 17 '19 at 8:39

You can do this from the admin (Magento 2.3.3):

Admin address validation

|improve this answer|||||
  • Where can i find this in admin? – Nayem Feb 5 at 5:35
  • @Nayem Stores -> Attributes -> Customer Address, and select "Street Address" from the list. – Niels Feb 6 at 8:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.