Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

ZipCode Validation Module

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #31  
Old 06-17-2004, 12:07 AM
 
xcell67 xcell67 is offline
 

Senior Member
  
Join Date: Dec 2003
Posts: 149
 

Default

Hi,
I'm on 3.5.8, my include/register.php doesn't have this syntax:

$smarty->assign("error",$error);

but it does have

if (!empty($reg_error))
$smarty->assign("reg_error",$reg_error);

should i just put the code after that?

thanks
Reply With Quote
  #32  
Old 06-17-2004, 09:58 AM
 
NuAlpha NuAlpha is offline
 

X-Adept
  
Join Date: Aug 2003
Location: US
Posts: 598
 

Default

That I am not sure of. I am guessing this difference isn't signifigant. You can try putting the code under that line ad give it a try. Test a user sign-up with and intentional bad zip code before using this on your live server.
__________________
X-Cart Pro 4.5.5 Platinum
X-Payments 1.0.6
PHP 5.3.14
MySQL 5.1.68
Apache 2.2.23
Reply With Quote
  #33  
Old 11-17-2004, 11:04 AM
  kangus's Avatar 
kangus kangus is offline
 

Senior Member
  
Join Date: Feb 2003
Posts: 160
 

Default Short form of ZIP check -

Replace the function in check_zipcode_js.tpl:

function check_zip_code_field(cnt, zip){
var valid = "0123456789-";
var hyphencount = 0;
if (cnt.options[cnt.selectedIndex].value=="US") {
if (zip.value.length!=5 && zip.value.length!=10 && zip.value!="") {
alert("Please enter your 5 digit or 5 digit+4 zip code formated like '12345-6789'.");
zip.focus();
return false;
}
for (var i=0; i < zip.value.length; i++) {
temp = "" + zip.value.substring(i, i+1);
if (temp == "-") hyphencount++;
if (valid.indexOf(temp) == "-1") {
alert("Invalid characters in your zip code. Please try again.");
zip.focus();
return false;
}
if ((hyphencount > 1) || ((zip.value.length==10) && ""+zip.value.charAt(5)!="-")) {
alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'. Please try again.");
zip.focus();
return false;
}
}
return true;
}else if (cnt.value=="CA") {
if (zip.value.length!=6 && zip.value.length!=7 && zip.value!="") {
alert("Ensure that you have 6 or 7 characters in your postal code")
zip.focus()
return false
}
}
return true
}
__________________
X-cart 3.3.1 ~ 4.0.18 4.1.1
PHP4/5 MySQL 4.1.10a/5.1
CENTOS 4.1 / SuSE 9.3 / MS Server
Authorize.Net Partner
Reply With Quote
  #34  
Old 11-17-2004, 12:29 PM
 
NuAlpha NuAlpha is offline
 

X-Adept
  
Join Date: Aug 2003
Location: US
Posts: 598
 

Default

This module is actually supposed to be able to take into account the presence or lack of hyphens in a zip+4 code within the PHP code.
__________________
X-Cart Pro 4.5.5 Platinum
X-Payments 1.0.6
PHP 5.3.14
MySQL 5.1.68
Apache 2.2.23
Reply With Quote
  #35  
Old 02-07-2005, 04:05 PM
 
NuAlpha NuAlpha is offline
 

X-Adept
  
Join Date: Aug 2003
Location: US
Posts: 598
 

Default

Here is a minor update to take care of a problem with Canadian zip code validation...
Code:
<?php ######################################### ## ## Validate Zipcode ## ## ######################################### ## Version: 1.2.8 (3/2/2004) ## Last updated: 2/7/2005 if (!defined('XCART_SESSION_START')) { header('Location: ../'); exit('Access Denied!'); } function validate_zipcode($zipcode,$country='') { $zipcode = trim($zipcode); // Prep by removing excess spaces. switch ($country) { case 'US': // Validate United States postal codes. if (strlen($zipcode) > 5 && strlen($zipcode) <= 10) { // If not length 5, then check for valid format. if (preg_match('/^([0-9]{5})([-=._\/\ ])?([0-9]{4})?$/', $zipcode, $checkZip)) { if (!empty($checkZip[3])) { // Is it a zip+4 code? if (empty($checkZip[2]) || $checkZip[2] != '-') $checkZip[2] = '-'; // Ensure that a dash is present in 9 digit zip code. $zipcode = $checkZip[1].$checkZip[2].$checkZip[3]; } else // Cause an error from incorrect length. $zipcode = ''; } else // No valid zip code matched. $zipcode = ''; } elseif (strlen($zipcode) < 5 || preg_match('/[[:alpha:]]/i',$zipcode)) // Check min length or presence of a letter. $zipcode = ''; # If none of the above, do not modify zipcode. It is a valid 5 numeric digits. break; case 'CA': // Validate Canadian postal codes. if (strlen($zipcode) >= 6 && strlen($zipcode) <= 7) { // Check for valid length. if (preg_match('/^([A-z0-9]{3})([-._\/\ ]?)([A-z0-9]{3})$/i', $zipcode, $checkZip)) { if ($checkZip[2] != ' ') $checkZip[2] = ' '; // Ensure that a space is between the two code segments. $zipcode = $checkZip[1].$checkZip[2].$checkZip[3]; } else // Cause an error from incorrect length. $zipcode = ''; } else // No valid zip code matched. $zipcode = ''; if (!empty($zipcode)) $zipcode = strtoupper($zipcode); // Capitalize alphabetic characters for Canadian postal code. break; } return $zipcode; } ?>
__________________
X-Cart Pro 4.5.5 Platinum
X-Payments 1.0.6
PHP 5.3.14
MySQL 5.1.68
Apache 2.2.23
Reply With Quote
  #36  
Old 02-14-2005, 08:32 AM
 
delphi delphi is offline
 

Senior Member
  
Join Date: Jul 2004
Posts: 185
 

Default

Have anyone tried this on Xcart 4.0.9 or 4.0.10 or 4.0.11?

I tried to put on 4.0.11, it is not working at all.
__________________
X-Cart Gold version 4.4.4
X-Cart directory /home/web/u/ugchweb/cart
PHP 5
MySQL server 5
Reply With Quote
  #37  
Old 02-14-2005, 09:53 AM
 
NuAlpha NuAlpha is offline
 

X-Adept
  
Join Date: Aug 2003
Location: US
Posts: 598
 

Default

I haven't had the opportunity to set this up with 4.0.x.
__________________
X-Cart Pro 4.5.5 Platinum
X-Payments 1.0.6
PHP 5.3.14
MySQL 5.1.68
Apache 2.2.23
Reply With Quote
  #38  
Old 04-03-2007, 06:52 AM
 
yoyo man yoyo man is offline
 

Newbie
  
Join Date: Mar 2007
Posts: 7
 

Default Re: ZipCode Validation Module

Just a heads up for anyone looking at this thread... this module may allow 9-digit US zip code validation, but that doesn't mean your realtime rates are going to be able to figure out what to do with a 9-digit zip code. Many of the rate charts only have the 5-digit zip codes, so having the full 9 may cause your shipping calculations to break.
__________________
...as a matter of fact it's all dark. v4.1.6
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 01:33 PM.

   

 
X-Cart forums © 2001-2020