Jump to content

Postal code validator error


John_k

Recommended Posts

Hello guys,

I have this problem with my validator that it won't recognise my postal code.

It shows red cross. I have set the backend setting to 'NNNN' for 4 x numbers. So it should work.

As far as I know it's a common problem - but the solutions out there don't work for me.

Please help me.

Regards  

Benjamin

Link to comment
Share on other sites

Hi

Here are the functions that validates postcode in prestashop

File: class/Validate.php

  public static function isPostCode($postcode)
    {
        return empty($postcode) || preg_match('/^[a-zA-Z 0-9-]+$/', $postcode);
    }

    /**
     * Check for zip code format validity
     *
     * @param string $zip_code zip code format to validate
     * @return bool Validity is ok or not
     */
    public static function isZipCodeFormat($zip_code)
    {
        if (!empty($zip_code)) {
            return preg_match('/^[NLCnlc 0-9-]+$/', $zip_code);
        }
        return true;
    }

 

It seems the regex in the isZipCodeFromat function can be modify for whatever you want.

Additionally the class/Address.php class definitions referrers isPostCode for validation before this function.

 

Also, as in the wiki page a the postcode should be at least 5 chars. Can be 6-7. It is here https://www.wikiwand.com/en/Postal_code. But I'm not sure. 

 

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...