sampsonzak Posted April 4, 2023 Share Posted April 4, 2023 Hi all, I've got some customers who provide their USA zip codes in NNNNN-NNNN, and so I have had to disable zip code validating for the US. But there must be a better way, but I cannot find it / find out how. Is it possible, to enable USA zip codes to be formatted, like below for example: NNNNN********** N = Essential & Required * = Optional. Unchecked / unvalidated. So the 5 numbers are essential, and it also allows an extra ~5 of any character to be added, without saying invalid ZIP code for those users who only provide me with the 5x number ZIP, and to also allow the other customers who provide the 9x ZIP code? How can I enable this? To allow my US zip codes to be more than 5 numbers without PS saying it's invalid to my customers? Thank you Link to comment Share on other sites More sharing options...
WebDesk Solution Posted April 6, 2023 Share Posted April 6, 2023 Hello @sampsonzak Please follow the steps below to change US postal code format: Please Log in to Prestashop back end Go to International > Locations Menu from the Sidebar panel Go to Countries Tab and search for United States from the listing and click on Edit button: https://prnt.sc/wfHyaQhz1Uxu Please change the format that you want to change: https://prnt.sc/D37WrgiK5k_G Click on Save button Clear the cache if required Hope this solution work for you..!! Thanks Link to comment Share on other sites More sharing options...
sampsonzak Posted April 6, 2023 Author Share Posted April 6, 2023 8 minutes ago, WebDesk Solution said: Hello @sampsonzak Please follow the steps below to change US postal code format: Please Log in to Prestashop back end Go to International > Locations Menu from the Sidebar panel Go to Countries Tab and search for United States from the listing and click on Edit button: https://prnt.sc/wfHyaQhz1Uxu Please change the format that you want to change: https://prnt.sc/D37WrgiK5k_G Click on Save button Clear the cache if required Hope this solution work for you..!! Thanks Hi, Thank you but this doesn't work. This would limit the zip code to NNNNN. I don't want it limited to NNNNN, I want it to be NNNNN required, but also to allow NNNNN****** * = wildcard, allowing numbers/text after this. But I don't know the symbol for wildcard, I have tried *** and it gives an error and does not let me save. e.g., I want the below to happen if submitted: 0000 = FAIL. not 5x numbers 00000 = SUCCESS. 5x numbers 00000-0000 = SUCCEED. 5x numbers & optional numbers Hope this makes sense. Thank you Link to comment Share on other sites More sharing options...
WebDesk Solution Posted April 7, 2023 Share Posted April 7, 2023 23 hours ago, sampsonzak said: Hi, Thank you but this doesn't work. This would limit the zip code to NNNNN. I don't want it limited to NNNNN, I want it to be NNNNN required, but also to allow NNNNN****** * = wildcard, allowing numbers/text after this. But I don't know the symbol for wildcard, I have tried *** and it gives an error and does not let me save. e.g., I want the below to happen if submitted: 0000 = FAIL. not 5x numbers 00000 = SUCCESS. 5x numbers 00000-0000 = SUCCEED. 5x numbers & optional numbers Hope this makes sense. Thank you Hello @sampsonzak As per your reply, we made some changes so please follow the steps below: Go to {{project_root_directory}}/override/classes and create a new file called Country.php and paste the following code in that file: <?php class Country extends CountryCore { public static $definition = [ 'table' => 'country', 'primary' => 'id_country', 'multilang' => true, 'fields' => [ 'id_zone' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true], 'id_currency' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId'], 'call_prefix' => ['type' => self::TYPE_INT, 'validate' => 'isInt'], 'iso_code' => ['type' => self::TYPE_STRING, 'validate' => 'isLanguageIsoCode', 'required' => true, 'size' => 3], 'active' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'], 'contains_states' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true], 'need_identification_number' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true], 'need_zip_code' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'], 'zip_code_format' => ['type' => self::TYPE_STRING], 'display_tax_label' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true], /* Lang fields */ 'name' => ['type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 64], ], 'associations' => [ 'zone' => ['type' => self::HAS_ONE], 'currency' => ['type' => self::HAS_ONE], ], ]; public function checkZipCode($zipCode) { if (empty($this->zip_code_format)) { return true; } $zipRegexp = '/^' . $this->zip_code_format . '$/ui'; $zipRegexp = str_replace('N', '[0-9]', $zipRegexp); $zipRegexp = str_replace('L', '[a-zA-Z]', $zipRegexp); $zipRegexp = str_replace('C', $this->iso_code, $zipRegexp); $zipRegexp = str_replace('*', '.*', $zipRegexp); return (bool) preg_match($zipRegexp, $zipCode); } } ?> Goto BO and set the format that type of postal code you need to set: https://prnt.sc/ChJb12c9XfsN Then please check on the frontend weather it allows the postal code with the format that you assigned or not: For Example, Postal code Format Set in BO (NNNNN******) 1) 0000 - Not Allowed 2) 00000 - Allowed 3) 00000-00000 - Allowed Hope this solution working fine for you...!! Thanks 2 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