Skip to main content

parse_se_workernummer

Function parse_se_workernummer 

Source
pub fn parse_se_workernummer(s: &str) -> Option<String>
Expand description

Parse a Sweden Workernummer.

The Swedish workeral identity number is the national identifier used for taxation, healthcare, banking, and similar purposes. It comes in two textual layouts:

  • 10-digit form: YYMMDDNNNC (or with a - / + separator between the date and the serial, e.g. 460324-3850). The + separator indicates the holder is over 100 years old.
  • 12-digit form: YYYYMMDDNNNC (or 19460324-3850).

Y/M/D are the birth-date digits, NNN is a 3-digit serial (odd = male, even = female under the historical convention), and C is the Luhn check digit computed over the 10 digits of the 10-digit form.

Non-digit characters are stripped before validation. The Luhn check uses left-to-right weights 2, 1, 2, 1, 2, 1, 2, 1, 2, 1; products ≥ 10 are reduced by digit-sum; the total mod 10 must be 0.

The canonical form preserves the input length: 10-digit input returns a 10-character string; 12-digit input returns a 12-character string. Records using mixed layouts will not match deterministically on this field, but they will still produce the correct Luhn validation.

§Examples

use worker_matcher::identifiers::parse_se_workernummer;

// Synthetic 10-digit workernummer with verified Luhn (sum 40, mod 10 = 0).
assert_eq!(
    parse_se_workernummer("4603243850"),
    Some("4603243850".to_string()),
);
assert_eq!(
    parse_se_workernummer("460324-3850"),
    Some("4603243850".to_string()),
);

// 12-digit form canonicalises with the century preserved.
assert_eq!(
    parse_se_workernummer("19460324-3850"),
    Some("194603243850".to_string()),
);

// Wrong Luhn:
assert_eq!(parse_se_workernummer("4603243851"), None);

// Wrong length, non-digits, empty:
assert_eq!(parse_se_workernummer("12345"),       None);
assert_eq!(parse_se_workernummer("ABCDEFGHIJ"),  None);
assert_eq!(parse_se_workernummer(""),            None);