okaty Posted September 19, 2013 Share Posted September 19, 2013 (edited) Hi, In my country our phone number has 10 digits. Some customer input a shorter , or longer number, and this is frustrating. Sometimes the customer checks his e-mail once every 2-3 days, and i need him to confirm the order as soon as possible. So my question is : How can i make the phone number field ask for a 10 digits number, not a minimum number or maximum number but just 10 digits. I tried to use the minimum 5 digits code from password inside the Validate.php and in the database to edit the 16 characters default length but it did not work I'm still a noob at this, so i will really appreciate your help PS version 1.5.5.0 Edited September 20, 2013 by okaty (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted September 19, 2013 Share Posted September 19, 2013 classes/Validate.php instead of this: public static function isPhoneNumber($number) { return preg_match('/^[+0-9. ()-]*$/', $number); } use this: public static function isPhoneNumber($number){ if (strlen($number)==10){ return preg_match('/^[+0-9. ()-]*$/', $number); }else{ return false; } } unfortunately without core change it isn't possible, solution is above 3 Link to comment Share on other sites More sharing options...
okaty Posted September 20, 2013 Author Share Posted September 20, 2013 Thank you! It works perfectly! Vekia is there a way to change the validate.php file in themes so when i update the php file will preserve ? [sOLVED] Link to comment Share on other sites More sharing options...
vekia Posted September 20, 2013 Share Posted September 20, 2013 Thank you! It works perfectly! Vekia is there a way to change the validate.php file in themes so when i update the php file will preserve ? [sOLVED] you're welcome and what you exactly mean by your second question? Sorry but i don't know what you want to achieve, can you shed some light on it please? Link to comment Share on other sites More sharing options...
okaty Posted September 20, 2013 Author Share Posted September 20, 2013 If a Prestashop update will come, i will lose the modified Validate.php. Is there a way to save the modified .php files for future updates. Like the .css and .tpl files which you put in your custom theme directory. Link to comment Share on other sites More sharing options...
vekia Posted September 20, 2013 Share Posted September 20, 2013 you can create override: http://doc.prestashop.com/display/PS15/Overriding+default+behaviors#Overridingdefaultbehaviors-Overridingaclass 1 Link to comment Share on other sites More sharing options...
patuga Posted January 6, 2016 Share Posted January 6, 2016 (edited) i tried that on 1.5.3.1 and it doesn't work. when fields are different from 10 it gives an error message saying phone is invalid. when it has 10 digits it gives an error 500 server error. also, how do i configure to have at least 6 digits, instead of 10 digits exactly? i have one phone number required (home or mobile) but if i use "space" on one of them, it accepts the input. and i don't want that can you guys help me? Edited January 6, 2016 by patuga (see edit history) Link to comment Share on other sites More sharing options...
Chrisi1321 Posted November 25, 2016 Share Posted November 25, 2016 Hi! Can anybody tell me the regex expression for phone numbers with a backslash in it? For example 12345/56778 should be allowed. This seems not to work... public static function isPhoneNumber($number) { return preg_match('/^[+0-9. ()-/]*$/', $number); } 1 Link to comment Share on other sites More sharing options...
Grindelf Posted June 8, 2017 Share Posted June 8, 2017 classes/Validate.php instead of this: public static function isPhoneNumber($number) { return preg_match('/^[+0-9. ()-]*$/', $number); } use this: public static function isPhoneNumber($number){ if (strlen($number)==10){ return preg_match('/^[+0-9. ()-]*$/', $number); }else{ return false; } } unfortunately without core change it isn't possible, solution is above Hello Vekia And about different sizes of phone number... like 11 numbers for mobile and 10 for home phone? Link to comment Share on other sites More sharing options...
DataKick Posted June 9, 2017 Share Posted June 9, 2017 And about different sizes of phone number... like 11 numbers for mobile and 10 for home phone? public static function isPhoneNumber($number){ $len = strlen($number); $min = 10; $max = 11; if ($len >= $min && $len <= $max){ return preg_match('/^[+0-9. ()-]*$/', $number); }else{ return false; } } this will check that phone number as at least $min characters and at most $max characters. Feel free to change min/max constants values 1 Link to comment Share on other sites More sharing options...
Grindelf Posted June 11, 2017 Share Posted June 11, 2017 I made tests and works. But for my case, i need that only numbers can be inserted. i need 11 numbers for mobile and 10 for home phone Because i see that the strings ()- are acceptable as counting on total number on field phone number. Link to comment Share on other sites More sharing options...
DataKick Posted June 12, 2017 Share Posted June 12, 2017 I made tests and works. But for my case, i need that only numbers can be inserted. i need 11 numbers for mobile and 10 for home phone Because i see that the strings ()- are acceptable as counting on total number on field phone number. Then try this one instead public static function isPhoneNumber($number){ $stripped = preg_replace('/[^0-9]/', '', $number); $len = strlen($stripped); $min = 10; $max = 11; if ($len >= $min && $len <= $max){ return preg_match('/^[+0-9. ()-]*$/', $number); }else{ return false; } } It still accepts phone numbers like "1-234-561-239" or "(123) 450 1111", but only if number of digits is 10 or 11. 1 Link to comment Share on other sites More sharing options...
Grindelf Posted June 13, 2017 Share Posted June 13, 2017 Then try this one instead public static function isPhoneNumber($number){ $stripped = preg_replace('/[^0-9]/', '', $number); $len = strlen($stripped); $min = 10; $max = 11; if ($len >= $min && $len <= $max){ return preg_match('/^[+0-9. ()-]*$/', $number); }else{ return false; } } It still accepts phone numbers like "1-234-561-239" or "(123) 450 1111", but only if number of digits is 10 or 11. Thank you very much Datakick. Works great. Where is the button to your tip please. Rita Link to comment Share on other sites More sharing options...
Recommended Posts