Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.89 KB | None | 0 0
  1. /**
  2.      * Checks for a valid postcode for a country
  3.      *
  4.      * @param   string  postcode
  5.      * @param   string  country
  6.      * @return  boolean
  7.      */
  8.     public static function is_postcode( $postcode, $country ) {
  9.         if ( strlen( trim( preg_replace( '/[\s\-A-Za-z0-9]/', '', $postcode ))) > 0 ) return false;
  10.         $postcode = strtoupper( trim( $postcode ));
  11.         $regex = isset( self::$postcode_regex[$country] ) ? self::$postcode_regex[$country] : '';
  12.  
  13.         if ( Jigoshop_Base::get_options()->get_option( 'jigoshop_enable_postcode_validating' ) == 'yes'
  14.             && $regex <> '' ) {
  15.  
  16.             $regex = '/' . $regex . '/';
  17.             jigoshop_log( "VALIDATE POSTCODE: country = " . $country . " = regex = " . $regex );
  18.  
  19.             switch ( $country ) {
  20.                 case 'GB':
  21.                     return self::is_GB_postcode( $postcode );
  22.                 default:
  23.                     $match = preg_match( $regex, $postcode );
  24.                     if ( $match !== 1 ) return false;
  25.             }
  26.         }
  27.         return true;
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement