Search code examples
phpopencartvqmod

Opencart 1.5.6.4 - How to enforce telephone field length


People visiting our store enter telephone numbers in all formats including prefixing 0, 00, +(countrycode).

By default(and strangely) Opencart registeration field for telephone allows alphanumeric values upto 32 characters in length.

Could anyone guide how can I go about setting the length to 10 digits on registeration and checkout pages.


Solution

  • You need to edit your register controller File. You can find your register controller file here catalog/controller/account/register.php

    Then in this file you can see below function in this file.

    protected function validate() {
    

    You can change below code :

    if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) {
    

    To

    if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 10)) {
    

    You need to change validation message as well. Just open this file : catalog/language/english/account/register.php

    $_['error_telephone']      = 'Telephone must be between 3 and 32 characters!';
    

    To

    $_['error_telephone']      = 'Telephone must be between 3 and 10 characters!';