Skip to content

Commit 591fab4

Browse files
Jaime Leemarko-bekhta
authored andcommitted
HV-2114 Add support for Korean foreigner RRN validation
(cherry picked from commit dca0549)
1 parent 475166a commit 591fab4

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

engine/src/main/java/org/hibernate/validator/internal/constraintvalidators/hv/kor/KorRRNValidator.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,16 @@
2222
*/
2323
public class KorRRNValidator implements ConstraintValidator<KorRRN, CharSequence> {
2424

25-
private static final List<Integer> GENDER_DIGIT = List.of( 1, 2, 3, 4 );
25+
// Gender digit in Korean Resident Registration Number (RRN):
26+
// 1: Male, born 1900–1999
27+
// 2: Female, born 1900–1999
28+
// 3: Male, born 2000–2099
29+
// 4: Female, born 2000–2099
30+
// 5: Foreign male, born 1900–1999
31+
// 6: Foreign female, born 1900–1999
32+
// 7: Foreign male, born 2000–2099
33+
// 8: Foreign female, born 2000–2099
34+
private static final List<Integer> GENDER_DIGIT = List.of( 1, 2, 3, 4, 5, 6, 7, 8 );
2635
// Check sum weight for ModUtil
2736
private static final int[] CHECK_SUM_WEIGHT = new int[] { 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2 };
2837
// index of the digit representing the gender
@@ -90,7 +99,7 @@ private static boolean isValidDate(final String rrn) {
9099
if ( month < 1 || month > 12 || day < 1 || day > 31 ) {
91100
return false;
92101
}
93-
return day <= 31 && ( day <= 30 || ( month != 4 && month != 6 && month != 9 && month != 11 ) ) && ( day <= 29 || month != 2 );
102+
return ( day <= 30 || month != 4 && month != 6 && month != 9 && month != 11 ) && ( day <= 29 || month != 2 );
94103
}
95104

96105
private static boolean isValidLength(String rrn) {

engine/src/test/java/org/hibernate/validator/test/internal/constraintvalidators/hv/kor/KorRRNValidatorAlwaysAttrTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ void setUp() {
3333
// valid RRN
3434
@Test
3535
void testBeforeOctober2020OnlyAttr() {
36-
3736
assertValidRRN( "861224-2567484" );
3837
assertValidRRN( "960223-2499378" );
3938
assertValidRRN( "790707-1133360" );
@@ -71,6 +70,14 @@ void invalidDate() {
7170
assertInvalidRRN( "999999-6609491" );
7271
}
7372

73+
@Test
74+
void testAlwaysForeignerGenderDigits() {
75+
assertValidRRN( "850101-5000005" );
76+
assertValidRRN( "920202-6000003" );
77+
assertValidRRN( "010101-7000006" );
78+
assertValidRRN( "030303-8000001" );
79+
}
80+
7481
// Invalid RRN Length
7582
@Test
7683
void invalidLength() {

engine/src/test/java/org/hibernate/validator/test/internal/constraintvalidators/hv/kor/KorRRNValidatorNeverAttrTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ void testNeverAttr() {
4747
assertValidRRN( "750519-1404601" );
4848
}
4949

50+
@Test
51+
void testNeverForeignerGenderDigits() {
52+
assertValidRRN( "850101-5000000" );
53+
assertValidRRN( "920202-6000000" );
54+
assertValidRRN( "010101-7000000" );
55+
assertValidRRN( "030303-8000000" );
56+
}
57+
5058
/**
5159
* The test succeeds without hyphen ('-')
5260
*/

0 commit comments

Comments
 (0)