validate

Validates an Indian Driving License number.

Normalisation applied before validation (in order):

  1. Trim leading/trailing whitespace

  2. Strip all internal whitespace (replace(Regex("\\s"), ""))

  3. Strip all hyphens (replace("-", "")) — hyphens are the primary separator in Digilocker DL strings

  4. Uppercase all characters

After normalisation, checks are applied in this order — first failing check wins:

Never throws. Returns ValidationResult.Invalid for all invalid inputs.

Pre-2013 DL formats are not supported — they will return InvalidReason.WRONG_LENGTH or InvalidReason.INVALID_FORMAT. See the class-level KDoc for details (R4 documented limitation).

Return

ValidationResult.Valid if the DL passes all structural checks, ValidationResult.Invalid with an appropriate InvalidReason otherwise.

Parameters

value

Raw DL string in any common input form (with or without hyphens/spaces, any case).

Samples

check(
    DL.validate("MH0120230012345") is ValidationResult.Valid ||
        DL.validate("MH0120230012345") is ValidationResult.Invalid,
)