validate
Validates an Indian Driving License number.
Normalisation applied before validation (in order):
Trim leading/trailing whitespace
Strip all internal whitespace (
replace(Regex("\\s"), ""))Strip all hyphens (
replace("-", "")) — hyphens are the primary separator in Digilocker DL stringsUppercase all characters
After normalisation, checks are applied in this order — first failing check wins:
InvalidReason.EMPTY if the result is blank
InvalidReason.WRONG_LENGTH if normalised length is not in {14, 15}
InvalidReason.INVALID_FORMAT if the string does not match
^[A-Z]{2}[0-9]{1,2}[0-9]{11}$InvalidReason.INVALID_PREFIX if the 2-letter state code is not in the 38-entry valid set
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
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,
)