Web Analytics

Fill the form & Get Installation Support

Any Question or Concerns?
Let's discuss

    In Magento 2, Firstname and Lastname are consider as customer entities.

    Customer’s Firstname and Lastname attributes have been added during Magento 2 installation.

    Firstname and Lastname attributes are mostly used in the registration page and customer form.

    Today, we are going to discuss, how to set minimum characters limit in Firstname and Lastname.

    We are going to set minimum 2 characters limit in Firstname and Lastname.

    For that, We need to change validate_rules column in customer_eav_attribute table for Firstname and Lastname attributes.

    By default Firstname and Lastname attributes contain validate_rules value as {“max_text_length”:255,”min_text_length”:1}

    We need to change that validate_rules column value to {“max_text_length”:255,”min_text_length”:2} for set minimum 2 characters.

    Let’s see server side and client side validations:

    1. Server side validation (After Form Submit)

    You can create extension to get this functionality.
    Extenson Name : Magemonkey_ValidateCustomerName

    Create registration.php file in app/code/Magemonkey/ValidateCustomerName/ and add below code.

    Create module.xml in app/code/Magemonkey/ValidateCustomerName/etc/ and add below code.

    Create UpgradeData.php file in app/code/Magemonkey/ValidateCustomerName/Setup/ and add below code.

    Above script will change validate_rules in customer_eav_attribute table to apply validation for server side.

    2. Client Side Validation (Before Form Submit)

    Override /vendor/magento/module-customer/view/frontend/templates/widget/name.phtml file to add client side validations.

    Add minimum-length-2 validate-length class in Firstname and Lastname input elements.

    So Firstname and Lastname inputes look like below in name.phtml file,

    Firstname input :

    Lastname input :


    Fill the below form if you have any Magento programming need.

      Recent Articles

      Author Info

      Author Image

      Magento Certified Developer

      Hire V. Brahmbhatt

      Get a Free Quote

        Connect With Us