public/wordpress/wp-content/plugins/wp-courseware/includes/functions/validation.php
/**
 * Checks for a valid postcode.
 *
 * @since 4.3.0
 *
 * @param string $postcode Postcode to validate.
 * @param string $country Country to validate the postcode for.
 *
 * @return bool
 */
Checks for a valid postcode.

@param string $postcode Postcode to validate.
@param string $country Country to validate the postcode for.

@return bool
Checks for a valid postcode . @param string $postcode Postcode to validate . @param string $country Country to validate the postcode for . @return bool
function wpcw_validation_is_postcode( $postcode, $country ) {
	if ( strlen( trim( preg_replace( '/[\s\-A-Za-z0-9]/', '', $postcode ) ) ) > 0 ) {
		return false;
	}
	switch ( $country ) {
		case 'AT' :
			$valid = (bool) preg_match( '/^([0-9]{4})$/', $postcode );
			break;
		case 'BR' :
			$valid = (bool) preg_match( '/^([0-9]{5})([-])?([0-9]{3})$/', $postcode );
			break;
		case 'CH' :
			$valid = (bool) preg_match( '/^([0-9]{4})$/i', $postcode );
			break;
		case 'DE' :
			$valid = (bool) preg_match( '/^([0]{1}[1-9]{1}|[1-9]{1}[0-9]{1})[0-9]{3}$/', $postcode );
			break;
		case 'ES' :
		case 'FR' :
			$valid = (bool) preg_match( '/^([0-9]{5})$/i', $postcode );
			break;
		case 'GB' :
			$valid = wpcw_validation_is_GB_postcode( $postcode );
			break;
		case 'JP' :
			$valid = (bool) preg_match( '/^([0-9]{3})([-])([0-9]{4})$/', $postcode );
			break;
		case 'PT' :
			$valid = (bool) preg_match( '/^([0-9]{4})([-])([0-9]{3})$/', $postcode );
			break;
		case 'US' :
			$valid = (bool) preg_match( '/^([0-9]{5})(-[0-9]{4})?$/i', $postcode );
			break;
		case 'CA' :
			$valid = (bool) preg_match( '/^([ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ])([\ ])?(\d[ABCEGHJKLMNPRSTVWXYZ]\d)$/i', $postcode );
			break;
		case 'PL':
			$valid = (bool) preg_match( '/^([0-9]{2})([-])([0-9]{3})$/', $postcode );
			break;
		case 'CZ':
		case 'SK':
			$valid = (bool) preg_match( '/^([0-9]{3})(\s?)([0-9]{2})$/', $postcode );
			break;
		default :
			$valid = true;
			break;
	}
	return apply_filters( 'wpcw_validate_postcode', $valid, $postcode, $country );
}
function wpcw_validation_is_postcode ( $ postcode , $ country ) { if ( strlen ( trim ( preg_replace ( '/[\s\-A-Za-z0-9]/' , '' , $ postcode ) ) ) > 0 ) { return false ; } switch ( $ country ) { case 'AT' : $ valid = ( bool ) preg_match ( '/^([0-9]{4})$/' , $ postcode ) ; break ; case 'BR' : $ valid = ( bool ) preg_match ( '/^([0-9]{5})([-])?([0-9]{3})$/' , $ postcode ) ; break ; case 'CH' : $ valid = ( bool ) preg_match ( '/^([0-9]{4})$/i' , $ postcode ) ; break ; case 'DE' : $ valid = ( bool ) preg_match ( '/^([0]{1}[1-9]{1}|[1-9]{1}[0-9]{1})[0-9]{3}$/' , $ postcode ) ; break ; case 'ES' : case 'FR' : $ valid = ( bool ) preg_match ( '/^([0-9]{5})$/i' , $ postcode ) ; break ; case 'GB' : $ valid = wpcw_validation_is_GB_postcode ( $ postcode ) ; break ; case 'JP' : $ valid = ( bool ) preg_match ( '/^([0-9]{3})([-])([0-9]{4})$/' , $ postcode ) ; break ; case 'PT' : $ valid = ( bool ) preg_match ( '/^([0-9]{4})([-])([0-9]{3})$/' , $ postcode ) ; break ; case 'US' : $ valid = ( bool ) preg_match ( '/^([0-9]{5})(-[0-9]{4})?$/i' , $ postcode ) ; break ; case 'CA' : $ valid = ( bool ) preg_match ( '/^([ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ])([\ ])?(\d[ABCEGHJKLMNPRSTVWXYZ]\d)$/i' , $ postcode ) ; break ; case 'PL' : $ valid = ( bool ) preg_match ( '/^([0-9]{2})([-])([0-9]{3})$/' , $ postcode ) ; break ; case 'CZ' : case 'SK' : $ valid = ( bool ) preg_match ( '/^([0-9]{3})(\s?)([0-9]{2})$/' , $ postcode ) ; break ; default : $ valid = true ; break ; } return apply_filters ( 'wpcw_validate_postcode' , $ valid , $ postcode , $ country ) ; }
Checks for a valid postcode.
Checks for a valid postcode .
// CA Postal codes cannot contain D,F,I,O,Q,U and cannot start with W or Z. https://en.wikipedia.org/wiki/Postal_codes_in_Canada#Number_of_possible_postal_codes