New blogMaking an AI Agent You Can Trust With Money

★ India · regex

Regex for UPI ID (VPA)

A UPI ID is a username, an @ and the payment provider's handle (okaxis, ybl, paytm, oksbi). Letters, digits, dots and hyphens are widely accepted in the username; underscores depend on the provider.

  • Runs in your browser
  • No signup

Try the upi id (vpa) pattern

Read it in plain English (best-effort)

  • ^start of a line
  • [a-zA-Z0-9]one character from: a–z, A–Z, 0–9
  • [a-zA-Z0-9._-]one character from: a–z, A–Z, 0–9, '.', '_', '-'
  • {1,255}between 1 and 255 of the previous
  • @the character '@'
  • [a-zA-Z]one character from: a–z, A–Z
  • [a-zA-Z0-9]one character from: a–z, A–Z, 0–9
  • {1,63}between 1 and 63 of the previous
  • $end of a line

One sample per line works well with the m flag on anchored patterns.

Waiting for a pattern
01

The pattern, piece by piece

/^[a-zA-Z0-9][a-zA-Z0-9._-]{1,255}@[a-zA-Z][a-zA-Z0-9]{1,63}$/
Pattern explanation
PartWhat it does
^[a-zA-Z0-9]the username starts with a letter or digit
[a-zA-Z0-9._-]{1,255}letters, digits, dots, underscores, hyphens
@exactly one at sign
[a-zA-Z][a-zA-Z0-9]{1,63}$the provider handle, e.g. okaxis or ybl
02

What it accepts and rejects

Every sample below is checked automatically in JavaScript and Python. The tester above is preloaded with all of them, one per line.

Should match
Should match
himanshu@okaxis✓
9876543210@ybl✓
jane.doe@oksbi✓
shop-123@paytm✓
rahul.k@ibl✓
merchant99@axl✓
Should not match
Should not match
himanshu✗
@okaxis✗
himanshu@✗
him anshu@okaxis✗
himanshu@ok axis✗
himanshu@@okaxis✗
himanshu#1@okaxis✗
03

Copy it into your code

RE2-safeNo lookarounds or backreferences, so the same pattern works in Go's RE2 engine and in Rust's regex crate.

const upiIdRe = /^[a-zA-Z0-9][a-zA-Z0-9._-]{1,255}@[a-zA-Z][a-zA-Z0-9]{1,63}$/;

export function isValidUpiId(value) {
  return upiIdRe.test(value.trim());
}
04

When not to use regex for this

Only the UPI network can confirm an ID exists and show the account holder's name. Use your payment gateway's VPA validation API before collecting money.

05

Questions engineers actually ask

Are underscores allowed in UPI IDs?
It depends on the app or bank. Some accept them, some don't, so a permissive pattern plus gateway verification is safest.
Does this check the handle is a real bank?
No. Handles are added over time; verify with your payment gateway instead of keeping a hard-coded list.
What is catastrophic backtracking?
Some patterns, usually nested quantifiers like (a+)+, make a backtracking engine try an exponential number of paths on input that almost matches. The tester stops any run after 300ms, so a bad pattern can't freeze your tab. In production, that same pattern can take down a server (a ReDoS attack).
06

Sources

Formats were checked on 8 November 2026. Rules change; the official issuer wins if it disagrees.

07

More india patterns

08

More from the workbench

Fine print

Tools: on the house.
Engineer: by the hour.

The regex was free. Code that doesn't need one is the upgrade: typed schemas, validated once at the edge, trusted everywhere after.

I'm Himanshu, an AI and full-stack engineer. I build MVPs, AI agents and the growth plumbing around them for early-stage startups.