Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Checks for a valid postcode for a country
- *
- * @param string postcode
- * @param string country
- * @return boolean
- */
- public static function is_postcode( $postcode, $country ) {
- if ( strlen( trim( preg_replace( '/[\s\-A-Za-z0-9]/', '', $postcode ))) > 0 ) return false;
- $postcode = strtoupper( trim( $postcode ));
- $regex = isset( self::$postcode_regex[$country] ) ? self::$postcode_regex[$country] : '';
- if ( Jigoshop_Base::get_options()->get_option( 'jigoshop_enable_postcode_validating' ) == 'yes'
- && $regex <> '' ) {
- $regex = '/' . $regex . '/';
- jigoshop_log( "VALIDATE POSTCODE: country = " . $country . " = regex = " . $regex );
- switch ( $country ) {
- case 'GB':
- return self::is_GB_postcode( $postcode );
- default:
- $match = preg_match( $regex, $postcode );
- if ( $match !== 1 ) return false;
- }
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement