mk2-pronat Posted August 21 Share Posted August 21 Hello, I would like to limit the client phone number to a minim of 10 digits when they place an order or create an account. I found something about this topic here but(in the link below) it's from 2017 so i was wondering if this is still valid. I am not a programmer but i would think that limiting to a minimum amount of characters in the phone number field would be implemented in the theme or back-office by now because it causes a lot of problems when contacting someone who misspelled their email for example and since we sell food products, time is important. So can anyone help me out with this? Quote https://www.prestashop.com/forums/topic/276105-solved-phone-number-fixed-length/ Link to comment Share on other sites More sharing options...
imjulien.dev Posted August 21 Share Posted August 21 Hello, This solution is still valid, and you can implement it. If you want a minimum of 10 characters, you need to replace the function with: public static function isPhoneNumber($number){ return preg_match('/^[+0-9. ()-]*$/', $number) && strlen($number) > 10; } You can replace ">" with "<" or "==" for an exact string length. Have a nice day, Julien Link to comment Share on other sites More sharing options...
Knowband Plugins Posted August 22 Share Posted August 22 Hi, To validate the phone number to be atleast 10 digit numbers, you need to modify the isPhoneNumber() function present at the below path- classes/Validate.php Use below code for the function- public static function isPhoneNumber($number) { if (empty($number)) { return false; } $digitsOnly = preg_replace('/\D/', '', $number); if (strlen($digitsOnly) < 10) { return false; } // The original phone number validation logic return preg_match('/^[+0-9. ()-]*$/', $number); } Regards. Link to comment Share on other sites More sharing options...
mk2-pronat Posted August 26 Author Share Posted August 26 Thank you both for the reply. I was away, so i couldn't answer quicker. Before i test this, i have another question, will this affect anything else like the phone numbers that are already saved in PrestaShop? My concerns are with the existing data. I usually avoid manipulating the core files because most of the time it comes with other headaches. But as far as I researched, and it seems you also confirmed, this is not possible in back-office. So the question remains, did anyone encounter problems after implementing this? I'm guessing limiting phone numbers or adding a minimum length requirement is not all that uncommon. Thank you again for the help so fare. Link to comment Share on other sites More sharing options...
Knowband Plugins Posted August 26 Share Posted August 26 Hi, Modifying the phone validation to require a minimum of 10 digits won't affect existing phone numbers but will block updates to those with fewer than 10 digits. It's safer to implement this change via a module or override rather than directly modifying core files to avoid issues with future updates or other dependencies. Test thoroughly before applying the change to your live environment. Regards. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now