Skip to content

Commit

Permalink
added isValid
Browse files Browse the repository at this point in the history
  • Loading branch information
seventhmoon committed Apr 12, 2021
1 parent 765fce1 commit 263fcff
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ class HkidValidator {
private val acceptedChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ "
private val hkidRegex = Regex("[A-Z]{1,2}\\d{6}")

@ExperimentalStdlibApi
fun isValid(id: String, checksum: Char) : Boolean{
return try {
calcCheckDigit(id) == checksum
}catch (e : IllegalArgumentException){
false
}
}

@ExperimentalStdlibApi
fun calcCheckDigit(input: String): Char {
if (input.matches(hkidRegex)) {
Expand Down

0 comments on commit 263fcff

Please sign in to comment.