Magento phone number should accept special character like (-) and should limit to 15 characters but currently it is accepting 10 characters only

In checkout_index_index.xml

<item name="validation" xsi:type="array">                                                                        
    <item name="min_text_length" xsi:type="number">10</item>                                                                         
    <item name="max_text_length_phone" xsi:type="number">15</item>                                                                        
    <item name="validate-number" xsi:type="number">0</item>                                                                    
</item>

and then in vendor/magento/module_ui/view/base/web/js/lib/validation/rules.js

"max_text_length_phone": [ 
        function (value, params) { 
            return !_.isUndefined(value) && value.length <= +params; 
        }, 
        $.mage.__('Phone number cannot exceed 15 characters.') 
    ], 

the above code is for validation text and for adding regex as we require, so in our case this (number with hypens allowed with max length of 15) For, that in Magento_Ui/web/js/lib/validation/rules.js

"validate-number": [
        function(value) {
            return utils.isEmptyNoTrim(value) || (!isNaN(utils.parseNumber(value)) && /^[0-9-s]+$/.test(value));
        },
        $.mage.__('Please enter a valid number in this field.')
    ],

Leave a comment

Your email address will not be published. Required fields are marked *