Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

No Spaces (Postal/Zip Code)


Guest

Recommended Posts

Hey folks,

 

Im using a Fedex module that requires the postal code (canada format: 0X0 X0X), to have no spaces.

 

Is there a way I can modify the check field feature so that if a space is detected, it returns an error indicating a restricted character?

 

Thanks!

 

Aaron

Link to comment
Share on other sites

I know not which specific module you are using. Mine is modified for MVS. It contains no validation.

 

create_account.php has the following:

 

if (strlen($postcode) < ENTRY_POSTCODE_MIN_LENGTH) {
  $error = true;
  $messageStack->add('create_account', ENTRY_POST_CODE_ERROR);
}

 

maybe you could convert it to something like:

 

 

if (strlen($postcode) < ENTRY_POSTCODE_MIN_LENGTH) {
  $error = true;
  $messageStack->add('create_account', ENTRY_POST_CODE_ERROR);
if (!strpos(' ', $postcode) === false) {
  $messageStack->add('create_account', 'No Spaces Please'); // this could be entered as ENTRY_POST_CODE_ERROR_SPACES and defined elsewhere.
}
}

Link to comment
Share on other sites

This is what I have to format postal/zip codes for Canada and USA ... but it adds a space in the middle of the Cdn postal code. I am sure you can easily take the space out. You will need to add it to the Account Address Add and Edit areas also so they don't change them there also.

 

 

	if (strlen($street_address) < ENTRY_STREET_ADDRESS_MIN_LENGTH) {
  $error = true;

  $messageStack->add('create_account', ENTRY_STREET_ADDRESS_ERROR);
}

if (strlen($postcode) < ENTRY_POSTCODE_MIN_LENGTH) {
  $error = true;

  $messageStack->add('create_account', ENTRY_POST_CODE_ERROR);
}
//if a USA zipcode lets test a bit;
if ($country == '223' ){
//validate zipcode
$zip = $postcode;
$len = strlen($zip);
	switch ($len){
		case 5:
			if (ereg ("[0-9][0-9][0-9][0-9][0-9]",$zip) !=1) {
			$error = true;
			$messageStack->add('create_account', ENTRY_POST_CODE_ERROR_A);
			}
			break;
		case 10:
			if (ereg ("[0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]",$zip) !=1) {
			$error = true;
			$messageStack->add('create_account', ENTRY_POST_CODE_ERROR_B);
			}
			break;
			default:
			$error = true;
			$messageStack->add('create_account', ENTRY_POST_CODE_ERROR_C);

	}
   }
	if ($country == '38'){
   // welcome to Canada!  K0L 2L0
 $postcode =  strtoupper($postcode);
 $postcode=str_replace(" ","",$postcode);
 $postcode= substr ( $postcode, 0, 3) . " " . substr ( $postcode, 3 ,3 );
$len = strlen($postcode);

	switch ($len){
		case 7:
			if (ereg ("[A-Z][0-9][A-Z][ ][0-9][A-Z][0-9]",$postcode) !=1) {
			$error = true;
			$messageStack->add('create_account', ENTRY_POST_CODE_ERROR_CAN);
			}
			break;

			default:
			$error = true;
			$messageStack->add('create_account', ENTRY_POST_CODE_ERROR_CAN_B);

	}
   }

 

 

Then in english.php I have

 

 

define('ENTRY_POST_CODE', 'Post Code/Zip Code:');
define('ENTRY_POST_CODE_ERROR', 'Your Post Code must contain a minimum of ' . ENTRY_POSTCODE_MIN_LENGTH . ' characters.');
define('ENTRY_POST_CODE_ERROR_A', 'Your 5 Digit Post Code must contain all numbers in the USA!');
define('ENTRY_POST_CODE_ERROR_B', 'Your USA 5+4 Post Code must be all numbers and in the form 12345-1234!');
define('ENTRY_POST_CODE_ERROR_C', 'Your USA Post Code must be 5 digits (12345) or 5+4 digits (12345-1234)! ');
define('ENTRY_POST_CODE_ERROR_CAN', 'Your Canadian Postal Code must be in the form A1B 2C3 ! ');
define('ENTRY_POST_CODE_ERROR_CAN_B', 'Your Canadian Post Code had the wrong number of characters. It needs to be in the form A1B 2C3! ');

Link to comment
Share on other sites

Hi there, and thanks for the script! I ahve it installed and working the way it is supposed to. Ive been try to modify to to detect spaces and remove them instead of detecting no space, and inserting on after the 3 character. Ive played a bit, but having nothing figure out yet. Im guess that the script below is where the modifications need to be made. Any suggestion??

 

// welcome to Canada! K0L 2L0

$postcode = strtoupper($postcode);

$postcode=str_replace(" ","",$postcode);

$postcode= substr ( $postcode, 0, 3) . " " . substr ( $postcode, 3 ,3 );

$len = strlen($postcode);

 

switch ($len){

case 7:

if (ereg ("[A-Z][0-9][A-Z][ ][0-9][A-Z][0-9]",$postcode) !=1) {

$error = true;

$messageStack->add('create_account', ENTRY_POST_CODE_ERROR_CAN);

}

break;

 

default:

$error = true;

$messageStack->add('create_account', ENTRY_POST_CODE_ERROR_CAN_B);

 

}

}[/code]

 

 

TRY_POST_CODE_ERROR_CAN_B', 'Your Canadian Post Code had the wrong number of characters. It needs to be in the form A1B 2C3! ');

Link to comment
Share on other sites

$postcode= substr ( $postcode, 0, 3) . " " . substr ( $postcode, 3 ,3 );

 

Is adding a space .. try

 

// $postcode= substr ( $postcode, 0, 3) . " " . substr ( $postcode, 3 ,3 );

 

Just commenting it out.

 

Also to match you need ..

 

case 7:
if (ereg ("[A-Z][0-9][A-Z][ ][0-9][A-Z][0-9]",$postcode) !=1) {

 

To be ..

 

case 6:
if (ereg ("[A-Z][0-9][A-Z][0-9][A-Z][0-9]",$postcode) !=1) {

 

I'm pretty certain that the above is correct.

Link to comment
Share on other sites

This is what I have to format postal/zip codes for Canada and USA ...

I think I will update my script. Thanks for a tighter way.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...