Skip to content

Validation Name is not working

Actually, I add validation of alpha-num there it shows the Magento default validation message there. I want to add my custom message there.

Validation is working

app/design/frontend/Theme/CustomTheme/Magento_Customer/templates/widget/name.phtml

Here is my code

<div class="field field-name-firstname required">
                    <label class="label" for="<?= $block->escapeHtmlAttr($block->getFieldId('firstname')) ?>"><span><?= $block->escapeHtml($block->getStoreLabel('firstname')) ?></span></label>
                    <div class="control">
                        <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="input-text <?= $block->escapeHtmlAttr($block->getAttributeValidationClass('firstname')) ?>" <?= ($block->getAttributeValidationClass('firstname') == 'required-entry') ? ' data-validate="{required:true, alphanumeric:true}"' : '' ?>>
                    </div>



 <div class="field field-name-lastname required">
                    <label class="label" for="<?= $block->escapeHtmlAttr($block->getFieldId('lastname')) ?>"><span><?= $block->escapeHtml($block->getStoreLabel('lastname')) ?></span></label>
                    <div class="control">
                        <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="input-text <?= $block->escapeHtmlAttr($block->getAttributeValidationClass('lastname')) ?>" <?= ($block->getAttributeValidationClass('lastname') == 'required-entry') ? ' data-validate="{required:true, alphanumeric:true}"' : '' ?>>
                    </div>