2

How can I change telephone field input type validation on check out onepage ?

Currently it takes input numeric with no space. I want to change it space with numbers

As an example,

current input format is: 1234567899999

But when i try this input format: 123 45468 99999

it is not working. What should I do to format this number?

3

Magento uses Prototype library to manage form validation of input fields. This comes in handy, because all you need to do when writing custom form is to assign a valid class names to your input fields, and pass the form id to VarienForm object.

you need add css class validate-phoneStrict at field which will do this type validation. you need to remove validate-number etc validation

You need see js field validation at js\prototype\validation.js

        <input type="tel" name="billing[telephone]" 
    value="<?php echo $this->escapeHtml($this->getAddress()->getTelephone()) ?>"
     title="<?php echo $this->__('Telephone') ?>" class="validate-phoneStrict
     input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('telephone') ?>"
 id="billing:telephone" />

and you can also do below format:

(123) 456-7890 or 123-456-7890
1
  • for reference: the two telephone validation classes and their regEx from validation.js: validate-phoneStrict = /^(\()?\d{3}(\))?(-|\s)?\d{3}(-|\s)\d{4}$/ validate-phoneLax = /^((\d[-. ]?)?((\(\d{3}\))|\d{3}))?[-. ]?\d{3}[-. ]?\d{4}$/
    – asherrard
    Jun 3 '16 at 19:26

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.