-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lagt på validering på orgnummer (#176)
* lagt på validering på orgnummer * lagt på endring
- Loading branch information
1 parent
759d9e9
commit 69fdbf0
Showing
4 changed files
with
67 additions
and
5 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
soknad/src/main/java/no/nav/k9/søknad/felles/type/OrganisasjonsNummerValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package no.nav.k9.søknad.felles.type; | ||
|
||
public final class OrganisasjonsNummerValidator { | ||
|
||
private OrganisasjonsNummerValidator() { | ||
} | ||
|
||
public static boolean erGyldig(String orgnummer) { | ||
|
||
// Skal inneholde 9 siffer og kun tall | ||
if (orgnummer == null || (orgnummer = orgnummer.trim()).length() != 9) { // NOSONAR | ||
return false; | ||
} | ||
|
||
int sisteSiffer = Character.getNumericValue(orgnummer.charAt(orgnummer.length() - 1)); | ||
|
||
return getKontrollSiffer(orgnummer) == sisteSiffer; | ||
} | ||
|
||
private static int getKontrollSiffer(String number) { | ||
int lastIndex = number.length() - 1; | ||
int sum = 0; | ||
|
||
for (int i = 0; i < lastIndex; i++) { | ||
sum += Character.getNumericValue(number.charAt(i)) * getVektTall(i); | ||
} | ||
|
||
int rest = sum % 11; | ||
|
||
return getKontrollSifferFraRest(rest); | ||
} | ||
|
||
private static int getVektTall(int i) { | ||
int[] vekttall = {3, 2, 7, 6, 5, 4, 3, 2}; | ||
return vekttall[i]; | ||
} | ||
|
||
private static int getKontrollSifferFraRest(int rest) { | ||
if (rest == 0) { | ||
return 0; | ||
} | ||
return 11 - rest; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters