سؤال

How can i add validations for only alphabets in First name and Last name fields in Customer registration form?

هل كانت مفيدة؟

المحلول

Extend name.phtml file in your theme as below and add letters-only validation:-

app\design\frontend\VendorName\themename\Magento_Customer\templates\widget\name.phtml

First Name:-

<input type="text" id="<?= $block->escapeHtmlAttr($block->getFieldId('firstname')) ?>"
                   name="<?= $block->escapeHtmlAttr($block->getFieldName('firstname')) ?>"
                   value="<?= $block->escapeHtmlAttr($block->getObject()->getFirstname()) ?>"
                   title="<?= $block->escapeHtmlAttr($block->getStoreLabel('firstname')) ?>"
                   class="letters-only input-text <?= $block->escapeHtmlAttr($block->getAttributeValidationClass('firstname')) ?>" <?php if ($block->getAttributeValidationClass('firstname') == 'required-entry') echo ' data-validate="{required:true}"' ?>>

Last Name:-

<input type="text" id="<?= $block->escapeHtmlAttr($block->getFieldId('lastname')) ?>"
                   name="<?= $block->escapeHtmlAttr($block->getFieldName('lastname')) ?>"
                   value="<?= $block->escapeHtmlAttr($block->getObject()->getLastname()) ?>"
                   title="<?= $block->escapeHtmlAttr($block->getStoreLabel('lastname')) ?>"
                   class="letters-only input-text <?= $block->escapeHtmlAttr($block->getAttributeValidationClass('lastname')) ?>" <?php if ($block->getAttributeValidationClass('lastname') == 'required-entry') echo ' data-validate="{required:true}"' ?>>

Now letters-only validation only accept letter in first name and last name, not numeric value.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top