Jump to content

Format phone number for one country


Wampas

Recommended Posts

Hello,

 

I need some help to modify validity.php file.

I have a module that automatically sends sms messages about order statuses. I need to ensure that user will enter his /her mobile phone number in correct format when registering an account or buying as a guest, but this restriction should be made only for one Country (in this case it is Lithuania)

 

I know that I have to change this code but I can`t figure how. For egzample phone number must be 37065012345

public static function isPhoneNumber($number)
    {
        return preg_match('/^[+0-9. ()-]*$/', $number);
    }

Who could help with it?

Thank you in advice.

Link to comment
Share on other sites

Yes, but I need that this would apply only for one country. Other countries should not be impacted. This modification will not allow to enter other country codes for example 371 or 372. There should be some IF statement.

Link to comment
Share on other sites

It's impossible to get the country inside that function. I think you'll need to override the processSubmitAccount function in controllers/front/AuthController.php and processSubmitAddress function in controllers/front/AddressController.php. I suggest finding the following code:
        if ($error_phone) {
            $this->errors[] = Tools::displayError('You must register at least one phone number.');
        }

And adding some code after it that checks the country and phone number. In AddressController.php, this is easy, since you can use $address->id_country. In AuthController.php, it's harder, since you'll have to create the $address object yourself. Look at the code after // Preparing addresses to see how it's done there.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...