Jump to content

Invalid Postcode Error


Recommended Posts

Somewhere while setting up Prestashop 1.4 I had to enter the postcode in a format of either letters on numbers which were referenced as L or N. In the UK we have 4 ways of entering postcodes, LN NLL, LNN NLL, LLNN NLL and LLNL NLL (some London postcodes).

We could only enter one way and chose LLNN NLL, now anyone with one of the above postcodes other than this format can not register or place an order because they get the following error:

There is 1 error :
1. Zip/ Postal code is invalid.
Must be typed as follows: AA00 0AA

Any ideas anyone?

***EDIT***

After 2 days I managed to work out the problem. The problem was caused after I added UK as a shipping destination. There is a postcode area which states: 'National zip code (L for a letter, N for a number and C for the Iso code), e.g., NNNNN for France. No verification if undefined.'

Because it has an asterik by this field I assumed it had to be filled. It doesn't. UK users need to leave it blank

  • Like 1
Link to comment
Share on other sites

  • 4 months later...

Somewhere while setting up Prestashop 1.4 I had to enter the postcode in a format of either letters on numbers which were referenced as L or N. In the UK we have 4 ways of entering postcodes, LN NLL, LNN NLL, LLNN NLL and LLNL NLL (some London postcodes).<br/><br/>We could only enter one way and chose LLNN NLL, now anyone with one of the above postcodes other than this format can not register or place an order because they get the following error:<br/><br/>There is 1 error :<br/>1. Zip/ Postal code is invalid.<br/>Must be typed as follows: AA00 0AA<br/><br/>Any ideas anyone?<br/><br/>***EDIT***<br/><br/>After 2 days I managed to work out the problem. The problem was caused after I added UK as a shipping destination. There is a postcode area which states: 'National zip code (L for a letter, N for a number and C for the Iso code), e.g., NNNNN for France. No verification if undefined.' <br/><br/>Because it has an asterik by this field I assumed it had to be filled. It doesn't. UK users need to leave it blank

 

 

Thanks for that, I cannot find a way of making the the postcode mandatory, but it does not have to be of a particular format. Any ideas?

Link to comment
Share on other sites

  • 1 year later...

This definitely is not solved! We need to be able to ensure that UK buyers have inserted a postcode without having to enter a zip code format in the admininstration area. As stated above there is currently no way to do this and it is causing me to lose sales, if a buyer goes through to PayPal without a postcode they come back with an error!

Link to comment
Share on other sites

  • 2 months later...
  • 1 year later...

well after searching  allday

I cannot believe how many have asked about this problem accross the site, some threads started 4 yes 4 years ago and its not been addressed.

I wonder if making/inventing 6 different countries (not sure what to call them yet) with the different postcode formats would be the way to go, very unproffessional but i cannot think of any other solution.

 

unless there is a secret sociaty out there that are under orders not to divulge the answer.

 

I also wonder how many uk prestashop owners  are out there and if its such a small number that the problem has no urgency

Link to comment
Share on other sites

  • 5 months later...
  • 4 months later...
  • 7 months later...

This issue is still not solved.

 

Yes it's easy to set it so that Prestashop does not require a postcode.

 

But, I do need UK users to be required to enter a postcode in order for our shipping process to work. 

I also need to be able to set up validation for UK postcodes - to do this we need to be able to enter multiple postcode formats for one country.

 

This is a basic requirement for UK shipping!

 

Does anyone have any advice?

Link to comment
Share on other sites

I started to evaluate PS yesterday and it seems really good other than this postcode issue that came to light in my first test.

Like everyone else, I've had a google and there doesn't seem to be a sensible solution ready to hand.

I've cribbed together my own fix which, with the postcodes I've already tried, seems to work ok. I'm sure someone out there will find a postcode that this doesn't work for. If that is the case - then just modify and add an additional regex.

My solution.

Back up the file js/validate.js

then modify the validate_isPostCode function to read:

function validate_isPostCode(s, pattern, iso_code)
{
	if (typeof iso_code === 'undefined' || iso_code == '')
		iso_code = '[A-Z]{2}';
	if (typeof(pattern) == 'undefined' || pattern.length == 0)
		pattern = '(([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z])))) [0-9][A-Za-z]{2}))';
	else
	{
		var replacements = {
			' ': '(?:\ |)',
			'-': '(?:-|)',
			'N': '[0-9]',
			'L': '[a-zA-Z]',
			'C': iso_code
		};

		for (var new_value in replacements)
			pattern = pattern.split(new_value).join(replacements[new_value]);
	}
	var reg = new RegExp('^' + pattern + '$');
	return reg.test(s);
}

Like I say, this seems to work for me......hope it helps.

  • Like 5
Link to comment
Share on other sites

I am having the same problem, some countries work fine, but most of them don't.  I have tried going into Localization-Countries and left the zip/postal code format field empty. I have tried the fix above, and this one: https://www.prestash...+zip +incorrect


 


Still no luck.  I had a look at http://forge.prestas...owse/PSCSX-4852  but I'm not sure how to proceed.  By "You need to update your theme and more specifically this file https://raw.githubus...esManagement.js" does it mean just to to replace the statesManagement page?


 


My version is 1.6.1.0, using the default theme and no modules other that the native modules.  Any further help would be appreciated.


  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

I think I may have an answer. It involves using the module Shipping Cost by Postcode, creating a new zone (e.g. Scottish Highlands & Islands) in the Shipping Cost By Postcode module and then entering every relevant UK postcode range manually. (I suspect there may be a quicker way to upload the postcodes, if you know where to look). 

 

So for the UK Postal service's Zone 2 (Scottish Highlands & Islands) I am entering ranges such as HS1 0AA to HS1 9ZZ, HS2 0AA to HS2 9ZZ etc. I am also entering the same without the space for people who enter it incorrectly eg HS10AA to HS19ZZ.

 

I think this could work (fingers crossed). I will try it and let you know ...

 

 

EDIT - sorry I should say, this doesn't solve the problem as stated in the original post.

 

But if what you are trying to achieve is to get Prestashop to work with UK postcodes, so you can set different shipping services for different areas (e.g. remote Scottish postcodes) then this could be an alternative solution

Edited by Enfys (see edit history)
Link to comment
Share on other sites

To validate any number or letter combination entered into the United Kingdom postcode field.

 

Since lowercase is automatically corrected uppercase you need to change this in the file:

 

js / validate.js

 

Modify line 125:

 

pattern = '[a-z 0-9-]+';

 

to

 

pattern = '[A-Z 0-9-]+';

 

Then in your Prestashop back office 'Localisation / Countires' Edit United Kingdom, And leave the 'Postal code format' Blank.

 

Hope this helps anyone XD

 

Alex

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

I can't believe that after 4 YEARS this problem is STILL not fixed!?

 

I'm having this problem right now, and nothing here has helped at all. No matter what I do customers cannot add a postal code in the address without it showing a RED ERROR cross next to it, and even though it still allows customers to progress with their order it is obviously going to make a lot of customers leave without completing.

 

This is THE MOST fundamental aspect of any shopping cart system and it needs to be fixed.

 

I can't imagine how many users have lost out on potentially thousands of sales because of this massive problem.

 

I now have a choice, either lose sales because people can't put their post code in, or lose sales by removing the post code field entirely and confusing my customers.

 

Please, can anyone explain how to make this infuriating error cross disappear?

Edited by RobbieBlokeToys (see edit history)
Link to comment
Share on other sites

Anyone?

 

All I need is to make the postcode field visible but not required, this shouldn't be too difficult to do but I can't find any information anywhere about this.

 

Obviously the error has persisted for 4 years without being remedied, so the best we can hope for now is to just get rid of the error warning when a customer tries to fill out the form.

My customers can proceed with that warning showing and it registers them anyway, I just know that I'm now going to be missing out on potentially thousands of £'s in sales as customers see that warning and leave thinking they can't complete the order.

 

Can no one from PS tell us how to make the postcode field visible but NOT REQUIRED? Please!?

Link to comment
Share on other sites

  • 2 weeks later...

After more than a week of getting no information or advice on this I have managed to sort this out myself. Thanks for nothing PS!

 

Chrishan's method of altering the .js worked for me, but you need to make sure you have not added anything into the postcode format field under countries > United Kingdom, and that you have Postcode Required set to visible, and that you have the postcode option in the list of fields for customers to use in the box below everything I just said.

 

And as I said before, this is really bad PS, this is a core function of any retail platform and you've really messed this up big time by making it far too complex and open to failure. The ordering process should be the simplest thing in any ecommerce program, without it all the pretty little functions are completely meaningless.

 

This needs to be changed so that such an important part of order creation doesn't require ten other settings to be perfectly spot on. All you need to do is give users the ability to create a custom form for the checkout process, one that doesn't rely on various other combinations of things to work as it should.

Link to comment
Share on other sites

I started to evaluate PS yesterday and it seems really good other than this postcode issue that came to light in my first test.

Like everyone else, I've had a google and there doesn't seem to be a sensible solution ready to hand.

I've cribbed together my own fix which, with the postcodes I've already tried, seems to work ok. I'm sure someone out there will find a postcode that this doesn't work for. If that is the case - then just modify and add an additional regex.

My solution.

Back up the file js/validate.js

then modify the validate_isPostCode function to read:

 

function validate_isPostCode(s, pattern, iso_code){	if (typeof iso_code === 'undefined' || iso_code == '')		iso_code = '[A-Z]{2}';	if (typeof(pattern) == 'undefined' || pattern.length == 0)		pattern = '(([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z])))) [0-9][A-Za-z]{2}))';	else	{		var replacements = {			' ': '(?:\ |)',			'-': '(?:-|)',			'N': '[0-9]',			'L': '[a-zA-Z]',			'C': iso_code		};		for (var new_value in replacements)			pattern = pattern.split(new_value).join(replacements[new_value]);	}	var reg = new RegExp('^' + pattern + '$');	return reg.test(s);}
Like I say, this seems to work for me......hope it helps.

This worked for me.

Thank you so much, I was on the point of giving up.

Edited by MrsDusty (see edit history)
Link to comment
Share on other sites

  • 1 month later...

Hello,

 

Maybe a little bit late but i changed the file statesmanagement.js (In your theme - js folder - Tools) with the following code and works till now without any problems. It's the same file earlier mentioned in this form but they forgot to put in the function binduniform so the checkboxes where not correct.

 

Here you have the whole file : (Please copy first the original statesmanagement.js file and change it then with this one)

 

 

statesmanagement.txt

  • Like 3
Link to comment
Share on other sites

  • 1 month later...

Hello,

 

Maybe a little bit late but i changed the file statesmanagement.js (In your theme - js folder - Tools) with the following code and works till now without any problems. It's the same file earlier mentioned in this form but they forgot to put in the function binduniform so the checkboxes where not correct.

 

Here you have the whole file : (Please copy first the original statesmanagement.js file and change it then with this one)

Yes that worked for me wel. I'm in the Netherlands!

Link to comment
Share on other sites

  • 2 weeks later...

Hello RobbieBlokeToys,

 

Go to js/validate.js  =>

 

function validate_isPostCode(s, pattern)
{
    if (typeof(pattern) == 'undefined' || pattern.length == 0)
        pattern = '[a-z 0-9-]+';
    else
    {
        var replacements = {
            ' ': '( |)',
            '-': '(-|)',
            'N': '[0-9]',
            'L': '[a-zA-Z]'
        };

        for (var new_value in replacements)
            pattern = pattern.split(new_value).join(replacements[new_value]);
    }

    var reg = new RegExp('^'+pattern+'$', 'i');
    return reg.test(s);
}

 

and also go to bottom of the same file:-

 

$(document).on('focusout', 'input.validate, textarea.validate', function() {
    if ($(this).hasClass('is_required') || $(this).val().length)
    {
        if ($(this).attr('name') == 'postcode' && typeof(countriesNeedZipCode[$('#id_country option:selected').val()]) != 'undefined')
            var result = window['validate_'+$(this).attr('data-validate')]($(this).val(), countriesNeedZipCode[$('#id_country option:selected').val()]);
        else
            var result = window['validate_'+$(this).attr('data-validate')]($(this).val())

        if (result)
            $(this).parent().removeClass('form-error').addClass('form-ok');
        else
            $(this).parent().addClass('form-error').removeClass('form-ok');
    }
});

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...

Actually you don't need to tamper with the validate.js. Try this:

 

At the end of the setCountries function in statesManagement.js, comment out the countries =  countriesPS; assignement.

Then look for the updateState function.

The lines

	if (typeof states !== 'undefined')
	{
		$(states).each(function(key, item){
                     $('#id_state' + (typeof suffix !== 'undefined' ? '_' + suffix : '')).append('<option value="' + parseInt(item.id) + '"' + (idSelectedCountry === item.id ? ' selected="selected"' : '') + '>' + item.name + '</option>');



should be

    if (typeof states !== 'undefined' && states.states.length && parseInt(states.contains_states))
    {
        $(states.states).each(function(key, item){
            $('#id_state' + (typeof suffix !== 'undefined' ? '_' + suffix : '')).append('<option value="' + parseInt(item.id_state) + '"' + (idSelectedState === item.id_state ? ' selected="selected"' : '') + '>' + item.name + '</option>');
        });



Edited by zombie process (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...

on the store i was just looking at, i replaced the /themes/themename/js/tools/statesmanagement.js with the statesmanagement.js from the defaullt-bootstrap of 1.6.1.5 and the problem is solved.  It makes sense the problem comes out for some, it may have been an early on 1.6 bug perhaps.  When people build themes based on the early theme and it has a bug, they suffer with it because store updates will not fix a theme error (unless it is the default-bootstrap and you choose to have the upgrade update the theme).

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

on the store i was just looking at, i replaced the /themes/themename/js/tools/statesmanagement.js with the statesmanagement.js from the defaullt-bootstrap of 1.6.1.5 and the problem is solved.  It makes sense the problem comes out for some, it may have been an early on 1.6 bug perhaps.  When people build themes based on the early theme and it has a bug, they suffer with it because store updates will not fix a theme error.

That one works for me. Thanks!

Link to comment
Share on other sites

  • 1 month later...

This is fixed

i can confirm as i tested it myself

 

as i cant paste a url for some strange reason and i cant even make a hyperlink  :angry:

search for [-] FO :Fix bug #PSCSX-5077, Country ISO code js validation.

search on github

 

regards

 

ps

í tested this on 1.6.1.6

I hope prestashop will add this to there own code

There statement of not editing files coz of future updates makes this fix useless for some of us

Edited by DGRL (see edit history)
Link to comment
Share on other sites

  • 5 years later...
On 8/28/2016 at 4:54 AM, DGRL said:

This is fixed

i can confirm as i tested it myself

 

as i cant paste a url for some strange reason and i cant even make a hyperlink  :angry:

search for [-] FO :Fix bug #PSCSX-5077, Country ISO code js validation.

search on github

 

regards

 

ps

í tested this on 1.6.1.6

I hope prestashop will add this to there own code

There statement of not editing files coz of future updates makes this fix useless for some of us

Hi i am facing same issue again. on  prestashop  1.7.8.2

 

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