DebugPointer
Published on

Regex for IFSC Code validation

Regex for IFSC Code validation

IFSC stands for Indian Financial System Code and is an 11-digit alphanumeric code that is used to identify and facilitate the transfer of money through RTGS (Real Time Gross Settlement) or NEFT (National Electronic Funds Transfer) between banks. It is used to identify the specific bank branch from which the transaction is to be made. In this article let's understand how we can create a regex for IFSC Code and how regex can be matched for a valid IFSC Code.

Regex (short for regular expression) is a powerful tool used for searching and manipulating text. It is composed of a sequence of characters that define a search pattern. Regex can be used to find patterns in large amounts of text, validate user input, and manipulate strings. It is widely used in programming languages, text editors, and command line tools.

Structure of an IFSC Code

A IFSC Code should have the following criteria and structure-

  • It should be 11 characters long.
  • The first four characters should be upper case alphabets.
  • The fifth character should be 0.
  • The last six characters usually numeric, but can also be alphabetic.

Regex for checking if IFSC Code is valid or not

Regular Expression-

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

Test string examples for the above regex-

Input StringMatch Output
KOTAK0125does not match
HDFC0002255matches
1234ICICI012does not match
SBIN0125620matches

Here is a detailed explanation of the above regex-

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

^ asserts position at start of a line
Match a single character present in the list below [A-Z]
{4} matches the previous token exactly 4 times
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case sensitive)
0 matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
Match a single character present in the list below [A-Z0-9]
{6} matches the previous token exactly 6 times
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case sensitive)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
$ asserts position at the end of a line
Global pattern flags
g modifier: global. All matches (don't return after first match)
m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)

Hope this article was useful to check if the string is a valid IFSC Code or not.