1

I want to remove this email validation and user can add mobile number in this field . How to apply this in my custom module..

Please help me...

enter image description here

4
  • It is email field. Not mobile number field. May 9 '17 at 6:54
  • please post your register.phtml code at your question description. May 9 '17 at 10:35
  • I put same file in my custom module and remove validate-email':true from email field and change input type = "email" May 9 '17 at 10:43
  • @RohanHapani Hi bro.. did you got the answer for this.. please share it here. i need it urgently
    – Ask Bytes
    Dec 3 '18 at 6:46
4

All validations are defined in

Magento2/lib/web/mage/validation.js

You can see validation-email

"validate-email": [
    function (v) {
        return $.mage.isEmptyNoTrim(v) || /^([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*@([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*\.(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]){2,})$/i.test(v);
    },
    'Please enter a valid email address (Ex: johndoe@domain.com).'
],

Override register.phtml to your theme

vendor/magento/module-customer/view/frontend/templates/form/register.phtml

remove 'validate-email':true from data-validate

data-validate="{required:true}"

<input type="email" name="email" autocomplete="email" id="email_address" value="<?php echo $block->escapeHtml($block->getFormData()->getEmail()) ?>" title="<?php /* @escapeNotVerified */ echo __('Email') ?>" class="input-text" data-validate="{required:true}">
11
  • It's not working :( May 9 '17 at 10:08
  • "Email" is not a valid email address. From where this message is executed? May 9 '17 at 10:14
  • data-validate is knockout js. All validations are coming from lib/web/mage/validation.js May 9 '17 at 10:20
  • You can see all validations in Magento2/lib/web/mage/validation.js file May 9 '17 at 10:24
  • how to remove it? May 9 '17 at 10:42
2

Additionally to the above answer you need to change the input type from type="email" to type="text", then it will not be validated anymore as email.

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.