0

How to validate phone number for billing address (should accept only number's and it should not exceed more then 10 digits) in magento2.1.7?

1

For billing address validation in magento 2.1.7, just check out the file path in

vendor/magento/module-checkout/Block/Checkout/LayoutProcessor.php

'telephone' => [
                            'validation' => [
                    //'mobileInD' => true,
                    'validate-number' => 0,
                    'min_text_length' => 10,   
                    'max_text_length' => 10,
             ],
                                'config' => [
                                    'tooltip' => [
                                        'description' => __('For delivery questions.'),
                                    ],
                                ],
                            ],
| improve this answer | |
0

You can try following code :

<input type="text" name="billing[telephone]" value="" title="Telephone" 
class="input-text  required-entry validate-length maximum-length-10 minimum- 
length-10 validate-digits" id="billing:telephone" placeholder="Mobile">

Hope this helps!

| improve this answer | |
  • Thanks Prasad, but i already got the answer. – Amy Nov 13 '18 at 6:12
0

You can apply the below validations according to your choice:

<validate>validate-length maximum-length-10</validate>

And

<validate>validate-phoneStrict</validate>

For example if you are applying validation form system configuration file then it should be like this:

<field id="number" translate="label" type="text" sortOrder="9" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Customer Service</label>
                <comment>Please enter an internationalized version of the phone number. For example +91 XXX XXXXXXX</comment>
                <validate>validate-phoneStrict validate-length maximum-length-10</validate>

</field>

See more validations here

| improve this answer | |
  • Thanks Ajwad, but i already got the answer. – Amy Nov 13 '18 at 6:11
  • Great, May be helpful for next searchers. – Ajwad Syed Nov 13 '18 at 6:17

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.