VPA

object VPA(source)

Validator and formatter for UPI Virtual Payment Addresses (VPA).

A VPA (also called UPI ID) is a public payment handle used in NPCI UPI transactions. Format: username@psp where username is an alphanumeric handle (dots, underscores, dashes allowed) and psp is the PSP/bank handle (e.g. ybl, oksbi, okhdfcbank).

Accepted input forms (all normalised before validation):

  • Lowercase: "user@ybl" — canonical NPCI form

  • Mixed case: "User@YBL" — normalised to "user@ybl"

  • Uppercase: "USER@YBL" — normalised to "user@ybl"

  • Whitespace padded: " user@ybl " — leading/trailing trimmed

Validation rules (post-normalization):

  • Maximum 50 characters total (NPCI spec)

  • Username minimum 3 characters

  • Exactly one @ separating username and PSP

  • Username: [a-z0-9._-]{3,}

  • PSP: [a-z0-9.-]+

PSP allowlist: Not enforced. NPCI adds PSPs regularly — a closed list would produce false negatives on legitimate handles. Structural validation only.

VPA is a public payment handle — shared openly to receive money. No mask() method is provided. See the KotIndia API design rationale for details.

This object is stateless and thread-safe.

Samples

VPA.validate("user@okaxis") // ValidationResult.Valid
VPA.format("User@OkAxis") // "user@okaxis"

Functions

Link copied to clipboard
fun format(value: String): String

Formats a VPA to canonical form: lowercase, no separators.

Link copied to clipboard
fun isValid(value: String): Boolean

Returns true if validate returns ValidationResult.Valid.

Link copied to clipboard

Validates a UPI Virtual Payment Address (VPA).