Skip to content

HV-2114 Add support for Korean foreigner RRN validation #1642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@
*/
public class KorRRNValidator implements ConstraintValidator<KorRRN, CharSequence> {

private static final List<Integer> GENDER_DIGIT = List.of( 1, 2, 3, 4 );
// Gender digit in Korean Resident Registration Number (RRN):
// 1: Male, born 1900–1999
// 2: Female, born 1900–1999
// 3: Male, born 2000–2099
// 4: Female, born 2000–2099
// 5: Foreign male, born 1900–1999
// 6: Foreign female, born 1900–1999
// 7: Foreign male, born 2000–2099
// 8: Foreign female, born 2000–2099
private static final List<Integer> GENDER_DIGIT = List.of(1, 2, 3, 4, 5, 6, 7, 8);
// Check sum weight for ModUtil
private static final int[] CHECK_SUM_WEIGHT = new int[] { 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2 };
// index of the digit representing the gender
Expand Down Expand Up @@ -90,7 +99,7 @@ private static boolean isValidDate(final String rrn) {
if ( month < 1 || month > 12 || day < 1 || day > 31 ) {
return false;
}
return day <= 31 && ( day <= 30 || ( month != 4 && month != 6 && month != 9 && month != 11 ) ) && ( day <= 29 || month != 2 );
return (day <= 30 || month != 4 && month != 6 && month != 9 && month != 11) && (day <= 29 || month != 2);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified the conditional statement.

}

private static boolean isValidLength(String rrn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ void testNeverAttr() {
assertValidRRN( "750519-1404601" );
}

@Test
void testNeverForeignerGenderDigits() {
assertValidRRN( "850101-5000000" );
assertValidRRN( "920202-6000000" );
assertValidRRN( "010101-7000000" );
assertValidRRN( "030303-8000000" );
}

/**
* The test succeeds without hyphen ('-')
*/
Expand Down