0

Can any one tell me how can i add validation for Tax/Vat number field. I want to make it numeric. https://prnt.sc/ouycdv What i have done till now in taxvat.phtml is

<input type="number" id="<?= $block->escapeHtmlAttr($block->getFieldId('taxvat')) ?>" name="<?= $block->escapeHtmlAttr($block->getFieldName('taxvat')) ?>" value="<?= $block->escapeHtmlAttr($block->getTaxvat()) ?>" title="<?= $block->escapeHtmlAttr(__('Tax/VAT number')) ?>" class="input-number <?= $block->escapeHtmlAttr($this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('taxvat')) ?>" <?php if ($block->isRequired()) echo ' data-validate="{required:true}"' ?> data-validate="{validate-number : true}">

But only this is not working. what more i have to do? how can i show error message

12
  • Open table eav_attribute and find attribute_code taxvat and get attribute_id from it
    – Rk Rathod
    Aug 20 '19 at 7:01
  • Open table customer_eav_attribute and find that attribute_id. update in validate_rules column
    – Rk Rathod
    Aug 20 '19 at 7:04
  • @RkRathod Is there any way to do this from code?
    – Nafsss
    Aug 20 '19 at 7:05
  • yes using upgradeData you can update attribute
    – Rk Rathod
    Aug 20 '19 at 7:06
  • 1
    @DavaGordon There is no option to make it numeric but
    – Nafsss
    Aug 20 '19 at 7:11
0

use the oninput event,eg:

<input type="number" oninput = "value=value.replace(/[^\d]/g,'')" id="<?= $block->escapeHtmlAttr($block->getFieldId('taxvat')) ?>" name="<?= $block->escapeHtmlAttr($block->getFieldName('taxvat')) ?>" value="<?= $block->escapeHtmlAttr($block->getTaxvat()) ?>" title="<?= $block->escapeHtmlAttr(__('Tax/VAT number')) ?>" class="input-number <?= $block->escapeHtmlAttr($this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('taxvat')) ?>" <?php if ($block->isRequired()) echo ' data-validate="{required:true}"' ?> data-validate="{validate-number : true}"> 
4
  • How to show error messager
    – Nafsss
    Aug 20 '19 at 7:25
  • what error message?
    – Tokey Tu
    Aug 20 '19 at 7:27
  • Message like 'Enter only numbers' .
    – Nafsss
    Aug 20 '19 at 7:28
  • use oninput event,just only input number.
    – Tokey Tu
    Aug 20 '19 at 7:29

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.