News:

Support the VirtueMart project and become a member

Main Menu

UK Postcode Format

Started by carbon-uk, October 26, 2011, 21:30:26 PM

Previous topic - Next topic

carbon-uk

OK so Royal Mail will not accept postcodes unless there is a space before the last 3 characters.

For example:

NW11DB - Should read NW1 1DB

Any suggestions on the best way to achieve this with fool proof accuracy? I guess input validation, but I'm new to PHP...

stinga

What don't they accept? I have never had anything rejected because of a missing space, I don't think there is any spec. that says there must be a space or how big.
Go to a different post office might solve the problem.... :-)
Stinga.
614869 products in 747 categories with 15749 products in 1 category.
                                             Document Complete   Fully Loaded
                Load Time First Byte Start Render   Time      Requests      Time      Requests
First View     2.470s     0.635s     1.276s          2.470s       31            2.470s      31
Repeat View  1.064s     0.561s     1.100s          1.064s       4             1.221s       4

carbon-uk

We genuinely have had a CSV file refused due to postcode format. They state that they have to have a space before the last 3 characters.

stinga

In that case you are going to need to first check that the country is UK.
I would go the other way and just make it the format I want, so remove spaces and then put a space before the last 3 bytes.
That will give you what you want... until you find a post code that has 2 or 4 bytes after the space! :-)

You are obviously doing something special to need the use of a csv file.
Stinga.
614869 products in 747 categories with 15749 products in 1 category.
                                             Document Complete   Fully Loaded
                Load Time First Byte Start Render   Time      Requests      Time      Requests
First View     2.470s     0.635s     1.276s          2.470s       31            2.470s      31
Repeat View  1.064s     0.561s     1.100s          1.064s       4             1.221s       4

AH

#4
My site customers (mainly UK) mistyped postcodes and addresses leaving me having to clean up the mess with my couriers.

Spent ages on regex checks and decided that I needed to improve the speed of address entry.

With this, I get a PAF (Postal Address Format) formatted address and save time on money on chasing up customers and couriers.

Easy to configure and greatly improves the Customer checkout experience.  Hopefully lowering cart abandonment rates.
Had a couple of queries and responses were within 1 hour of raising the query!!

I can even test this out with no upfront cost, you do of course have to pay a tiny amount for PAF lookup going forward but to me it is a small price to pay for less abandonments!

http://www.craftyclicks.co.uk/web-service/shopping-cart-plugins

Before you ask:-
I am NOT anything to do with this company, nor am I being paid for this post!! 
I just wanted to support service providers that actually provide a great service and hopefully keep them developing for Virtuemart!
Regards
A

Joomla 4.4.5
php 8.1

AH

If a UK customer gets the postcode set incorrectly it is a real pain!!

To ensure it gets entered in a recognisable format (from a uk PAF perspective)  you can use regex checking.

Update your administration/components/com_virtuemart/classes/ps_userfield.php

Around line 712 you will see this code:-

$optional_check = '';
if( VM_REGISTRATION_TYPE == 'OPTIONAL_REGISTRATION') {
$optional_check = '&& form.register_account.checked';
}
    // We have skipped email in the first loop above!
    // Now let's handle email address validation
    if( isset( $required_fields['email'] )) {
   
    echo '
if( !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(form.email.value))) {
alert( \''. str_replace("'","\\'",$VM_LANG->_('REGWARN_MAIL',false)) .'\');
return false;
}';

}



Just add the check for people from the UK for the postcode format:-
$optional_check = '';
if( VM_REGISTRATION_TYPE == 'OPTIONAL_REGISTRATION') {
$optional_check = '&& form.register_account.checked';
}

/// NEW CODE GOES HERE
   
// Added uk specific regex zip code check in user address!
        if( isset( $required_fields['zip'] )) {
echo '
if( form.country.value == "GBR"  && !(/^([a-zA-Z]{1,2}[0-9rR][0-9a-zA-Z]? [0-9][abd-hjlnp-uw-zABD-HJLNP-UW-Z]{2})$/.test(form.zip.value))) {
alert( \'Please enter a valid UK post code - e.g. NG17 8AA \');
return false;
}';
}

//quorvia end
///NEW CODE END

    // We have skipped email in the first loop above!
    // Now let's handle email address validation
   
    if( isset( $required_fields['email'] )) {





Enjoy!


Regards
A

Joomla 4.4.5
php 8.1

AH

Address lookup as a plugin in the UK is unlikely to be a free service as you have to pay for the PAF files in the first instance

You are looking for a "reverse" lookup, again this is PAF based, but I do not know of one for VM as customers buying stuff for themselves, tend to know their postcode.

The lookup aims to reduce the effort and errors for address input.

Maybe someone has other options, but I do not know of them for VM
Regards
A

Joomla 4.4.5
php 8.1

jimleeder123

I've got it validating TS1-TS5 but I want to exclude TS2. How can I do this?
Web Developer and blogger

Joomla 3.4.8  (2.5 on some)
VM 3.0.12
PHP 5.6 (5.4 on websites with Joomla 2.5)

http://jimleeder.co.uk

jimleeder123

Web Developer and blogger

Joomla 3.4.8  (2.5 on some)
VM 3.0.12
PHP 5.6 (5.4 on websites with Joomla 2.5)

http://jimleeder.co.uk

AH

Well done - regex is pretty straightforward and there are lots of testing tools on the net to see if you have got it correct
Regards
A

Joomla 4.4.5
php 8.1

jimleeder123

I've worked it out again. I used "&&" instead of "||" and it worked.

On a different subject, do you know how to force delivery rates in Virtuemart 1 based on the postcode?
Alternatively other websites I have need delivery fees decided by order totals.

Virtuemart 1 only allows for it to be decided by weight it seems.
Web Developer and blogger

Joomla 3.4.8  (2.5 on some)
VM 3.0.12
PHP 5.6 (5.4 on websites with Joomla 2.5)

http://jimleeder.co.uk

AH

You have to code the standard_shipping and some other stuff but I cannot really do this for you as mine does lots of other  bespoke stuff

You could try to see if http://www.gjcwebdesign.com/  has a relevant plugin for vm1
Regards
A

Joomla 4.4.5
php 8.1