Regex for IFSC Code Validation — Indian Bank Codes Explained

The Indian Financial System Code (IFSC) uniquely identifies every bank branch that participates in RBI electronic transfer systems like NEFT, RTGS, and IMPS. If you're building a payments form, payroll tool, or banking integration for Indian users, validating IFSC format before hitting a bank verification API saves both API calls and user frustration. This guide covers the exact format, a battle-tested regex, and implementation examples in JavaScript and Python.

Understanding the IFSC format

An IFSC code is always exactly 11 characters, structured as follows:

  • First 4 characters — uppercase letters identifying the bank (e.g. HDFC, SBIN, ICIC).
  • 5th character — always the digit 0, reserved by RBI for future use.
  • Last 6 characters — alphanumeric, identifying the specific branch.

An example valid code is HDFC0001234, where HDFC is the bank code and 001234 identifies the branch.

The IFSC regex pattern

^[A-Z]{4}0[A-Z0-9]{6}$

This pattern requires exactly four uppercase letters, a literal 0, and six trailing alphanumeric characters — no more, no less, thanks to the anchors.

JavaScript example

function isValidIFSC(code) {
  const ifscRegex = /^[A-Z]{4}0[A-Z0-9]{6}$/;
  const normalized = code.trim().toUpperCase();
  return ifscRegex.test(normalized);
}

console.log(isValidIFSC("hdfc0001234")); // true
console.log(isValidIFSC("HDFC1001234")); // false - 5th char must be 0
console.log(isValidIFSC("HDF0001234")); // false - only 3 letters at start

Python example

import re

IFSC_REGEX = re.compile(r"^[A-Z]{4}0[A-Z0-9]{6}$")

def is_valid_ifsc(code: str) -> bool:
    normalized = code.strip().upper()
    return bool(IFSC_REGEX.match(normalized))

print(is_valid_ifsc("sbin0000123"))  # True
print(is_valid_ifsc("SBIN000012"))   # False - only 5 trailing characters

SQL example for bulk validation

If you're cleaning a branch master table in PostgreSQL, you can flag invalid IFSC codes using a regex match directly in SQL:

SELECT branch_name, ifsc_code
FROM bank_branches
WHERE ifsc_code !~ '^[A-Z]{4}0[A-Z0-9]{6}$';

Common pitfalls

  • Allowing lowercase input without normalizing — IFSC codes in bank records are always uppercase.
  • Forgetting the fixed 0 in position five, which loosens the pattern and accepts invalid codes.
  • Treating a regex pass as branch existence confirmation. Always cross-check against the RBI IFSC list or a banking API before processing an actual transfer.

Frequently Asked Questions

What is the regex pattern for validating an IFSC code?

The standard regex is ^[A-Z]{4}0[A-Z0-9]{6}$. It matches four uppercase letters representing the bank, a literal zero reserved for future use, and six alphanumeric characters identifying the branch.

Why is the 5th character always zero in an IFSC code?

The Reserve Bank of India reserved the 5th character as a fixed 0 for potential future use in the IFSC numbering scheme. Every currently issued IFSC code has 0 in this position, so validating it strictly improves accuracy.

Can regex confirm an IFSC code belongs to a real bank branch?

No. Regex only validates the format — 11 characters matching the bank-code and branch-code structure. To confirm the code maps to an actual branch, you need to query the RBI IFSC list or a banking API such as Razorpay IFSC or the official RBI database.

Try the Free AI Regex Generator

Need a custom regex for another banking or financial field? Describe your validation rule in plain English and get a tested pattern instantly with Dev Brains AI's free AI Regex Generator.

Related articles