How can we limit the character of first name and last name of customer. For example I want only 30 characters are valid to enter in first & last name. As of now there is no limit on character we can add as many character we want.

Looking for advices Thanks

  • do you want to limit 30 character individually for first name and last name OR in combined name (first name + last name) ? Oct 12 '18 at 13:14
  • yes individually
    – Daniel_12
    Oct 12 '18 at 13:14
  • for individual , you can use maxlength property of text field of first name and last name like this link Oct 12 '18 at 13:16
  • no but how can we do this in magento 2. I am aware of maxlength="10" feature
    – Daniel_12
    Oct 12 '18 at 13:17
  • you need to override template file vendor/magento/module-customer/view/frontend/templates/widget/name.phtml and need to put maxlength property there. Oct 12 '18 at 13:23

Try This Code

<input type="text" name="first name" id="first_name"
       class="admin__control-text required-entry validate-alphanum-with-spaces validate-length maximum-length-30"
       maxlength="30" />

whatever you want set input field length,set in maxlength attribute


You need to override core template file vendor/magento/module-customer/view/frontend/templates/widget/name.phtml in your theme folder using this link -

How to override .phtml files in Magento 2

and need to put maxlength property in input text field of first name and last name as suggested here.


hope this helps.


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.