I prepared a code which masks the phone field. Since on some of our customer's website the customer does not enter input for phone field on register page, i need to put second condition to render this block apart from the "module enabled flag"

On customer_address_edit page the phone field is always required but on register page it is optional.

What is the best practice to do that ? enter image description here

1 Answer 1



Try this

<div class="field telephone">
            <label for="telephone" class="label"><span><?php /* @escapeNotVerified */ echo __('Phone Number') ?></span></label>
            <div class="control">
                <input placeholder="<?php /* @escapeNotVerified */ echo __('Phone') ?>" type="text" name="telephone" id="telephone" value="<?php echo $block->escapeHtml($block->getFormData()->getTelephone()) ?>" title="<?php /* @escapeNotVerified */ echo __('Phone Number') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('telephone') ?>">

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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