nabuchodonozor Posted February 14, 2016 Share Posted February 14, 2016 Hello guys, I need to do validation in phone number. I need 9 digits validation in my form. Im using presta 1.6. Please help me guys <3 Link to comment Share on other sites More sharing options...
tuk66 Posted February 16, 2016 Share Posted February 16, 2016 Change the Validate::isPhoneNumber method. Now, these characters are permitted (any number): 0-9. ()- 1 Link to comment Share on other sites More sharing options...
safa Posted February 16, 2016 Share Posted February 16, 2016 (edited) classes/validate.php isPhoneNumber () Edited February 16, 2016 by safa (see edit history) Link to comment Share on other sites More sharing options...
nabuchodonozor Posted February 16, 2016 Author Share Posted February 16, 2016 (edited) public static function isPhoneNumber(9) { return preg_match('/^[0-9]{0,9}$/', $number); } Is that correct now?I want to do something, that will be requiering to type 9 digits, because now somebody, can write only 1 digit in form... Edited February 16, 2016 by nabuchodonozor (see edit history) Link to comment Share on other sites More sharing options...
tuk66 Posted February 17, 2016 Share Posted February 17, 2016 You can test it at https://regex101.com Link to comment Share on other sites More sharing options...
nabuchodonozor Posted February 17, 2016 Author Share Posted February 17, 2016 I think that its not working Link to comment Share on other sites More sharing options...
safa Posted February 21, 2016 Share Posted February 21, 2016 replace like this. public static function isPhoneNumber($number) { preg_match('/^[+0-9. ()-]*$/', $number); return Tools::strlen($number) == 9 ; } Link to comment Share on other sites More sharing options...
nabuchodonozor Posted February 21, 2016 Author Share Posted February 21, 2016 (edited) I will try it ASAP. Which filles have I to delete too? Edited February 21, 2016 by nabuchodonozor (see edit history) Link to comment Share on other sites More sharing options...
safa Posted February 21, 2016 Share Posted February 21, 2016 I will try it ASAP. Which filles have I to delete too? you don't need any delete file . open this file classes/validate.php and replace this function public static function isPhoneNumber($number) Link to comment Share on other sites More sharing options...
nabuchodonozor Posted February 21, 2016 Author Share Posted February 21, 2016 Yes i know. I did this now. But there is no changes, I can still write 1 digit, maybe it have to took some time until form will update? Link to comment Share on other sites More sharing options...
safa Posted February 21, 2016 Share Posted February 21, 2016 i tested and it worked for me . you have any override files ? or maybe your current theme will use special validate function Link to comment Share on other sites More sharing options...
nabuchodonozor Posted February 21, 2016 Author Share Posted February 21, 2016 Im using default theme. I tried to override validate.php file but I didnt knew how to did it. So i think that there is no files after override. Can you upload your validate.php ? Link to comment Share on other sites More sharing options...
safa Posted February 22, 2016 Share Posted February 22, 2016 (edited) file is athacded , upload this file to /override/classes folder after delete this file /cache / class_index.php Validate.php Edited February 22, 2016 by safa (see edit history) Link to comment Share on other sites More sharing options...
nabuchodonozor Posted February 22, 2016 Author Share Posted February 22, 2016 Now its working! Thanks Bro. I have one more question. How can I now edit the message which is informing customer about this form. I mean that i want to do something that will show another error message than the default one. " Please enter full phone number 111-222-333" Or something like that. Link to comment Share on other sites More sharing options...
Petr Pánek Posted July 24, 2017 Share Posted July 24, 2017 (edited) replace like this. public static function isPhoneNumber($number) { preg_match('/^[+0-9. ()-]*$/', $number); return Tools::strlen($number) == 9 ; } This is not 100% corrert solution. This code will only check, if there are 9 characters, but not check if all characters are digits. Correct code is public static function isPhoneNumber($number) { return (preg_match('/^[+0-9. ()-]*$/', $number) AND strlen($number) == 9); } Edited July 24, 2017 by Petr Pánek (see edit history) 2 2 Link to comment Share on other sites More sharing options...
Petr Pánek Posted July 24, 2017 Share Posted July 24, 2017 If you want do also inline validation in the form, change the validate.js function validate_isPhoneNumber(s) this way: function validate_isPhoneNumber(s) { var reg = /^[+0-9. ()-]+$/; return (reg.test(s) && s.length == 9); } 2 1 Link to comment Share on other sites More sharing options...
nikos83 Posted April 11, 2021 Share Posted April 11, 2021 On 7/24/2017 at 1:48 PM, Petr Pánek said: This is not 100% corrert solution. This code will only check, if there are 9 characters, but not check if all characters are digits. Correct code is public static function isPhoneNumber($number) { return (preg_match('/^[+0-9. ()-]*$/', $number) AND strlen($number) == 9); } This is working! Thanks - anyone know where or how to customise error messages on this validation? At the moment I've got wrong format on error but I would like to add some extra text for clients... Link to comment Share on other sites More sharing options...
Daresh Posted February 12 Share Posted February 12 Hi guys! If you've already upgraded to PrestaShop 8, here is a free module that you can use to validate the phone number in a fancy way: Link to comment Share on other sites More sharing options...
goldies Posted October 26 Share Posted October 26 On 2/12/2024 at 1:18 PM, Daresh said: Hi guys! If you've already upgraded to PrestaShop 8, here is a free module that you can use to validate the phone number in a fancy way: IS IT AVAILABLE FOR ps 1.7? 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