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?
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.'),
],
],
],
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!
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