Skip to content

Commit d20d429

Browse files
R33D3M33Rrodrigoprimo
authored andcommitted
Add postcode validation for Slovenia (woocommerce#25174)
Add postcode validation for Slovenia
1 parent 5c85f3c commit d20d429

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

includes/class-wc-validation.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ public static function is_postcode( $postcode, $country ) {
9696
case 'NL':
9797
$valid = (bool) preg_match( '/^([1-9][0-9]{3})(\s?)(?!SA|SD|SS)[A-Z]{2}$/i', $postcode );
9898
break;
99-
99+
case 'SI':
100+
$valid = (bool) preg_match( '/^([1-9][0-9]{3})$/', $postcode );
101+
break;
100102
default:
101103
$valid = true;
102104
break;

tests/unit-tests/util/validation.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,15 @@ public function data_provider_test_is_postcode() {
107107
array( false, WC_Validation::is_postcode( '3852 sa', 'NL' ) ),
108108
);
109109

110-
return array_merge( $it, $gb, $us, $ch, $br, $ca, $nl );
110+
$si = array(
111+
array( true, WC_Validation::is_postcode( '1234', 'SI' ) ),
112+
array( true, WC_Validation::is_postcode( '1000', 'SI' ) ),
113+
array( true, WC_Validation::is_postcode( '9876', 'SI' ) ),
114+
array( false, WC_Validation::is_postcode( '12345', 'SI' ) ),
115+
array( false, WC_Validation::is_postcode( '0123', 'SI' ) ),
116+
);
117+
118+
return array_merge( $it, $gb, $us, $ch, $br, $ca, $nl, $si );
111119
}
112120

113121
/**

0 commit comments

Comments
 (0)