cancel
Showing results for 
Search instead for 
Did you mean: 

how can a make that phone number field on the delivery adress take only numbers

SOLVED
   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

how can a make that phone number field on the delivery adress take only numbers

Hello every one, i need to achive that the field "phone number" only accept numbers and not alphabetical characters. all your help and references will be helpfull

1 ACCEPTED SOLUTION

Accepted Solutions

Re: how can a make that phone number field on the delivery adress take only numbers

@edgar_salcedo1

 

You can use below shared workaround:

 

To validate number you can use validate-number in your module checkout_index_index.xml

<item name="telephone" xsi:type="array">
    <item name="config" xsi:type="array">
    <item name="tooltip" xsi:type="array">
        <item name="description" xsi:type="string" translate="true">For delivery questions</item>
    </item>
    </item>
    <item name="validation" xsi:type="array">
        <item name="min_text_length" xsi:type="number">10</item>
        <item name="max_text_length" xsi:type="number">10</item>
        <item name="validate-number" xsi:type="number">0</item>
    </item>
</item>

OR

 

form should be like

<form class="form contact"
  action="<?php /* @escapeNotVerified */ echo $block->getFormAction(); ?>"
  id="contact-form"
  method="post"
  data-hasrequired="<?php /* @escapeNotVerified */ echo __('* Required Fields') ?>"
  data-mage-init='{"validation":{}}'>

now in input field use data-validate="{'validate-number':true}"

Your input would look like:

 

<input type="text" data-validate="{'validate-number':true}"> 
Manish Mittal
https://www.manishmittal.com/

View solution in original post

2 REPLIES 2

Re: how can a make that phone number field on the delivery adress take only numbers

@edgar_salcedo1

 

You can use below shared workaround:

 

To validate number you can use validate-number in your module checkout_index_index.xml

<item name="telephone" xsi:type="array">
    <item name="config" xsi:type="array">
    <item name="tooltip" xsi:type="array">
        <item name="description" xsi:type="string" translate="true">For delivery questions</item>
    </item>
    </item>
    <item name="validation" xsi:type="array">
        <item name="min_text_length" xsi:type="number">10</item>
        <item name="max_text_length" xsi:type="number">10</item>
        <item name="validate-number" xsi:type="number">0</item>
    </item>
</item>

OR

 

form should be like

<form class="form contact"
  action="<?php /* @escapeNotVerified */ echo $block->getFormAction(); ?>"
  id="contact-form"
  method="post"
  data-hasrequired="<?php /* @escapeNotVerified */ echo __('* Required Fields') ?>"
  data-mage-init='{"validation":{}}'>

now in input field use data-validate="{'validate-number':true}"

Your input would look like:

 

<input type="text" data-validate="{'validate-number':true}"> 
Manish Mittal
https://www.manishmittal.com/

Re: how can a make that phone number field on the delivery adress take only numbers

should I edit the file and save it, with that will work?