german-insurance-number-validator
v1.0.6
Published
Angular 19–22 library to validate German health insurance numbers (Krankenversichertennummer / Versichertennummer / KVNR). Checksum logic tested on 100,000+ numbers. Includes a standalone input component and reactive-forms validator.
Maintainers
Keywords
Readme
german-insurance-number-validator
Validates German health insurance numbers — Krankenversichertennummer / Versichertennummer (KVNR): 1 letter + 9 digits with an official-style checksum.
The checksum logic has been tested against more than 100,000 German insurance numbers.
Requires Angular 19, 20, 21, or 22.
Terminology
| English | German | Abbreviation | | --- | --- | --- | | German health insurance number | Krankenversichertennummer, Versichertennummer | KVNR |
Features
- Standalone input component with label and built-in English error messages
- Reactive Forms validator (
germanInsuranceNumberValidator()) - Pure helper
isValidGermanInsuranceNumber()for use outside templates - Empty values are treated as valid (pair with
Validators.requiredwhen the field is mandatory) - Works with
formControl/formControlNameviaControlValueAccessor
Validation rules
| Rule | Detail |
| --- | --- |
| Length | Exactly 10 characters |
| Format | First character is a letter (A–Z, case-insensitive); the rest are digits |
| Checksum | Letter mapped to two digits (A = 01 … Z = 26), then alternate multiply by 1 and 2, cross-total, compare sum % 10 to the last digit |
Example of a valid number: A123456780.
Installation
npm install german-insurance-number-validatorPeer dependencies: @angular/core, @angular/common, and @angular/forms (Angular 19–22).
Standalone input component
import { Component } from '@angular/core';
import { FormControl, ReactiveFormsModule } from '@angular/forms';
import { GermanInsuranceNumberInputComponent } from 'german-insurance-number-validator';
@Component({
selector: 'app-profile-form',
imports: [ReactiveFormsModule, GermanInsuranceNumberInputComponent],
template: `
<german-insurance-number-input
[formControl]="insuranceNumber"
label="German insurance number"
[required]="true"
/>
`,
})
export class ProfileFormComponent {
insuranceNumber = new FormControl('');
}Input options
| Input | Type | Default | Purpose |
| --- | --- | --- | --- |
| label | string | German insurance number | Visible field label |
| placeholder | string | e.g. A123456789 | Input placeholder |
| required | boolean | false | Marks the field required and shows the required message |
| requiredMessage | string | German insurance number is required. | Override required error text |
| invalidMessage | string | Please enter a valid German insurance number. | Override checksum/format error text |
| inputId | string | auto-generated | Links the label to the input |
| showErrorsWhen | 'touched' \| 'dirty' \| 'submitted' | 'touched' | When to show validation messages |
Validator only
Use this when you already have your own input UI:
import { FormControl, Validators } from '@angular/forms';
import {
germanInsuranceNumberValidator,
VALIDATION_ERROR_KEY,
} from 'german-insurance-number-validator';
const control = new FormControl('', [
Validators.required,
germanInsuranceNumberValidator(),
]);
if (control.errors?.[VALIDATION_ERROR_KEY]) {
// invalid insurance number
}Invalid values set:
{ "validationError": "Please enter a valid German insurance number." }Pure utility
import { isValidGermanInsuranceNumber } from 'german-insurance-number-validator';
isValidGermanInsuranceNumber('A123456780'); // true
isValidGermanInsuranceNumber('A123456789'); // false
isValidGermanInsuranceNumber(''); // true (optional field)Reliability
The checksum algorithm used by this package has been tested over 100,000+ German insurance numbers.
License
MIT
