Kiến thức

How to Validate SWIFT/BIC Code Using RegEx?

A SWIFT/BIC code consists of 8-11 characters SWIFT follows a format that identifies your bank, country, location, and branch. A SWIFT code — is also called a BIC number.BIC is a standard format for Business Identifier Codes (BIC). It’s used to identify banks and financial institutions globally. These codes are used when transferring money between banks, in particular for international wire transfers or SEPA payments. Banks also use these codes to exchange messages with each other.

Format of SWIFT Code

A SWIFT/BIC is an 8-11 character code. That follows below architecture:

  1. It is an alphanumeric code.
  2. Its length may vary from 8 to 11 characters.
  3. The first four letters should be from the alphabet.
  4. After the first four letters, the next two letters should be from the alphabet.
  5. The next two letters can be either from the alphabet or numbers.
  6. The last three letters should be in numeric form i.e. from 0 to 9.
  7. It should not contain white spaces.

Example:

SWIFT_Code= AAAABB11222 OR AAAA-BB-11-222

Where,

  • The first four letters represent the bank, which usually looks like an abbreviated version of the bank name
  • The next two letters indicate the country where the bank is located.
  • The next two letters/numbers indicate the location of the bank’s main office. (It can be numbers or letters)
  • The next three letters identify a specific branch.

Approach

This problem can be solved using Regular Expression. Regex will validate the entered data and will provide the exact format. Below are steps that can be taken for the problem:

  1. Accept the string
  2. Create a regex pattern to validate the SWIFT code As written below:

regex=”^[A-Z]{4}[-]{0,1}[A-Z]{2}[-]{0,1}[A-Z0-9]{2}[-]{0,1}[0-9]{3}$”

Where,

^ : Starting of the string

[A-Z]{4} : This expression will match 4 of the preceding items in the range form “A” to “Z”.

[-]{0,1} : This expression will match one or zero preceding item if it is a hyphen symbol(-).

[A-Z0-9]{2] : This expression will match two of the preceding item in the range from “A” to “Z” and 0 to 9.

$ : Indicates the end of the string.

Code

Below is the code implementation of the above approach.

Chuyên gia chia sẻ  Top 10 sàn Bitcoin Việt Nam hàng đầu Hot nhất 2024

Time Complexity: O(N) for each test case, where N is the length of the given string. Auxiliary Space: O(1)

So by the above discussion, We can sum up the correct SWIFT code format given below:

  1. AAAABB11222
  2. AAAA-BB-11-222
  3. AAAABBCC222
  4. AAAA-BB-CC-222

Đánh giá bài viết post

Phạm Văn Sỹ

Tôi là Phạm Văn Sỹ chuyên gia uy tín trong lĩnh vực kinh tế và kinh doanh là sinh viên của trường Đại học Ngoại Thương. Với kiến thức sâu rộng sau 12 năm ở bên ngoài thương trường thị trường tôi mong muốn chia sẻ các kiến thức chuyên sâu hữu ích dành cho mọi người.

Related Articles

Back to top button