如何使用正規表示式驗證IFSC代碼?
印度金融系統代碼是縮寫。參與電子資金轉移系統的印度銀行分行由一個特殊的11位元字元代碼進行識別。印度儲備銀行在網路交易中使用此代碼在銀行之間轉移資金。 IFSC程式碼分為兩個部分。銀行由前四個字元進行標識,而分行由最後六個字元進行標識。 NEFT(全國電子資金轉移)、RTGS(即時毛額結算)和IMPS(即時支付服務)是一些需要IFSC代碼的電子交易。
Method
使用正規表示式驗證IFSC程式碼的一些常見方法有:
檢查長度是否正確。
檢查前四個字元。
Check the fifth character.
#Check the last six characters .
#方法1:檢查正確的長度
11 characters should make up the IFSC Code. To determine the length, use the following regular expression −
^.{11}$
This regular expression matches any 11 characters.
文法
使用正規表示式驗證IFSC程式碼,可以使用語法來檢查正確的長度−
^([A-Z]{4}[0][A-Z0-9]{6})$
^ Marks the beginning of the string
#([A-Z]{4} 匹配IFSC代碼的前4個字符,應為大寫字母
[0] 符合IFSC代碼的第五個字符,應為零
#[A-Z0-9]{6} Matches the last 6 characters of IFSC code, which should be either uppercase letters or numbers.
$ Marks the end of the string
這個正規表示式保證了IFSC代碼中包含11個字符,其中包括4個大寫字母,一個零,然後是6個大寫字母或數字。
演算法
Here is a detailed procedure for utilising regular expressions to validate an IFSC code's length −
Step 1 − Describe the regular expression pattern for an IFSC code: An IFSC code is an 11-character alphanumeric code. The bank code is represented by first four characters, bch 代碼, and always-zero fifth character. An IFSC code's regular expression pattern is as follows−
[A-Z]{4}[0] [A-Z0-9]{6} $
步驟2 - 檢查正規表示式模式:可以使用線上正規表示式測試工具,如regex101.com和regexr.com來測試正規表示式模式。將模式輸入到測試工具中,然後輸入IFSC代碼來檢查是否與模式相符。
步驟 3 − 驗證IFSC程式碼的長度:在進行模式測試後,您必須驗證IFSC程式碼的長度。 Python中的len()方法可以用來確定IFSC程式碼是否是需要的確切長度,也就是11個字元。
第四步驟 - 使用正規表示式模式:在確定長度之後,您可以使用正規表示式模式來確定IFSC程式碼的格式是否符合預期。若要在Python中將此模式應用於IFSC程式碼,請使用re模組。
Example 1
在這種情況下,IFSC程式碼使用正規表示式[A-Z]40[A-Z0-9]6$進行驗證。正規表示式符合下列模式−
代碼的前四個字母(從[A-Z])必須是大寫。
The number zero (0) must be the fifth character.
#最後六個字元([A-Z0-9]6$] 可以是大寫字母或數字。
#使用regex_match函數來匹配ifsc_code字串和正規表示式。如果字串與正規表示式匹配,則代碼被認為是有效的。如果不匹配,則被認為是無效的。
#include <iostream> #include <regex> using namespace std; int main() { string ifsc_code = "SBIN0000123"; // Example IFSC code regex ifsc_regex("^[A-Z]{4}0[A-Z0-9]{6}$"); // Regular expression for IFSC code if (regex_match(ifsc_code, ifsc_regex)) { cout << "Valid IFSC code\n"; } else { cout << "Invalid IFSC code\n"; } return 0; }
Output
#Valid IFSC code
Method 2: Check the first four characters
The first four characters of IFSC Code identify the bank. One can use a regular expression to check that the first four characters are alphabets.
^[A-Z]{4}
這個正規表示式符合任四個大寫字母。
文法
這是一個用於檢查IFSC程式碼前四個字元的正規表示式 -
^([A-Z]{4})
這個正規表示式使用以下語法 -
^ 符合字串的開頭。
[A-Z] 符合任何大寫字母。
{4} 指定前面的模式應該剛好出現四次。
() Creates a capture group to extract the matched text.
#這個正規表示式將符合任何以四個大寫字母開頭的字串。要驗證整個IFSC程式碼,需要檢查除了前四個字元之外的其他條件。
演算法
Here is a step-by-step algorithm for validating the first four characters of an IFSC code using a regular expression −
#步骤1 − 为IFSC代码的前四个字符指定正则表达式模式。前四个字符应仅使用字母,其中前两个字符代表银行代码,后两个字符代表位置代码。可以用正则表达式表示为[A-Z]4。
Step 2 − Obtain the input IFSC code that requires validation.
第三步 - 删除提供的IFSC代码的前四个字符。
Step 4 − Verify whether the extracted first four characters fit the specified pattern using the regular expression match () function. The input IFSC code is regarded as valid if the match is successful and the validation is successful. If there is no match, the validation is unsuccessful and the input IFSC code is deemed invalid.
Note: This algorithm only checks the first four characters of the IFSC code. The complete validation of the IFSC code requires additional checks for the remaining characters.
Example 2
In this illustration, the IFSC code we want to validate is represented by the string "ifsc_code." Then, in accordance with the IFSC code format, we build a regular expression pattern using the std::regex class that matches any string that begins with four letters.
然后,使用std::regex_search函数检查ifsc_code字符串是否与正则表达式模式匹配。如果匹配成功,则输出一个通知,说明IFSC代码是合法的。如果不匹配,则输出一个通知,说明IFSC代码无效。
#include <iostream> #include <regex> int main() { std::string ifsc_code = "ABCD123456"; std::regex pattern("^[A-Za-z]{4}"); if (std::regex_search(ifsc_code, pattern)) { std::cout << "IFSC code is valid." << std::endl; } else { std::cout << "IFSC code is invalid." << std::endl; } return 0; }
Output
IFSC code is valid.
Method 3: Check the fifth character
The fifth character of the IFSC Code is a zero (0) and is reserved for future use. One can use a regular expression to check that the fifth character is a zero.
^.{4}0
这个正则表达式匹配任意四个字符后面跟着一个零。
语法
To check the fifth character and validate an IFSC code using a regular expression, you can use the following general syntax −
^[A-Z]{4}[0]{1}[A-Z0-9]{6}$
^ and $ represent the start and end of the string, respectively, ensuring that the entire string matches the pattern.
[A-Z]{4} 匹配正好四个大写字母字符。这表示银行代码。
[0]{1} 匹配正好一个零。这代表了IFSC代码中的第五个字符。
[A-Z0-9]{6} 匹配恰好六个字符,可以是大写字母或数字。这代表分行代码。
总的来说,该模式匹配以四个大写字母开头,后跟一个零,并以六个大写字母或数字结尾的IFSC代码。
算法
这里有一个使用正则表达式检查IFSC代码第五个字符的算法 -
步骤 1 − 输入 IFSC 代码。
Step 2 − Define the regular expression pattern for IFSC codes: "^.{4}.{1}.*$"
Step 3 − Use the regular expression pattern to match the input IFSC code.
Step 4 − If there is a match −
获取IFSC代码的第五个字符。
Check if the fifth character is valid according to your criteria (e.g., a specific range of characters, specific characters, etc.).
If the fifth character is valid: - Output "IFSC code is valid."
If the fifth character is not valid: - Output "IFSC code is not valid."
第五步 - 如果没有匹配 -
Output "IFSC code is not valid."
Example 3
的中文翻译为:示例 3
一个在C++中的示例,展示了如何利用正则表达式来检查IFSC代码的第五个字符,而不需要用户输入
在这个例子中,IFSC代码“SBIN0001234”被用作样本代码。为了匹配IFSC代码的结构,使用了一个正则表达式模式[A-Za-z]40[A-Z0-9]6$。提取第五个字符,然后验证代码是否符合该模式。如果第五个字符是大写字母,则被接受。否则,它是无效的。
#include <iostream> #include <regex> int main() { std::string ifscCode = "SBIN0001234"; // Example IFSC code // Regular expression pattern to match IFSC code std::regex pattern("^[A-Za-z]{4}0[A-Z0-9]{6}$"); // Check if the IFSC code matches the pattern if (std::regex_match(ifscCode, pattern)) { // Extract the fifth character char fifthCharacter = ifscCode[4]; // Perform validation on the fifth character if (std::isalpha(fifthCharacter) && std::isupper(fifthCharacter)) { std::cout << "Fifth character is valid: " << fifthCharacter << std::endl; } else { std::cout << "Fifth character is invalid: " << fifthCharacter << std::endl; } } else { std::cout << "Invalid IFSC code." << std::endl; } return 0; }
Output
Fifth character is invalid: 0
Method 4: Check the last six characters
IFSC代码的最后六个字符标识分支机构。您可以使用正则表达式来检查最后六个字符是否为字母数字。
^.{4}[A-Z0-9]{6}$
This regular expression matches any four characters followed by six alphanumeric characters.
By combining the above regular expressions, you can create a regular expression to validate the entire IFSC Code.
^[A-Z]{4}0[A-Z0-9]{6}$
这个正则表达式匹配任何有效的IFSC代码。
语法
The regular expression pattern ^[A-Z]{4}\d{6}$ consists of the following components −
^ indicates the start of the string.
[A-Z]{4} 匹配正好四个大写字母字符。
\d{6} 匹配正好六个数字。
$ indicates the end of the string.
算法
使用正则表达式检查IFSC代码的最后六个字符,您可以按照以下算法进行操作 -
步骤 1 − 定义一个正则表达式模式,该模式匹配 IFSC 编码的最后六个字符。例如,该模式可以是 "[A-Z0-9]{6}"。
步骤 2 - 创建一个用于测试的样本 IFSC 代码列表。这些代码应该是有效的 IFSC 代码。
第三步 - 对列表中的每个IFSC代码 -
Extract the last six characters from the IFSC code.
使用正则表达式模式来匹配提取的字符。
If the match is successful, the last six characters are valid.
If the match fails, the last six characters are not valid.
第四步 - 打印每个IFSC代码的结果(有效或无效)。
Example 4
的中文翻译为:示例 4
在这里,我们定义了一个正则表达式模式[A-Z0-9] $,它匹配任何一组大写字母(A-Z)或数字(0-9),恰好出现六次(6),在字符串的末尾($)。然后,为了检查ifscCode字符串是否与模式匹配,我们使用std::regex_match()。在这种情况下,我们发布"IFSC code is valid",而在没有匹配的情况下,我们打印"IFSC code invalid"。
#include <iostream> #include <regex> int main() { std::string ifscCode = "SBIN0001234"; // Example IFSC code // Regular expression pattern to match the last six characters of an IFSC code std::regex pattern("[A-Z0-9]{6}$"); // Checking if the last six characters of the IFSC code match the pattern if (std::regex_match(ifscCode, pattern)) { std::cout << "IFSC code is valid." << std::endl; } else { std::cout << "IFSC code is invalid." << std::endl; } return 0; }
Output
IFSC code is invalid.
Conclusion
总之,利用正则表达式来验证IFSC代码可以是一种实用且有效的技术,以确保代码的格式正确。任何不符合所需模式的输入都可以使用正则表达式标记为无效,以定义IFSC代码必须遵循的模式。
Prior to applying regular expressions to validate an IFSC code, it's critical to comprehend the format and structure of the code. The bank code is represented by the first four characters of the IFSC code, the branch code by the next six characters, and the zero as the fifth character.
以上是如何使用正規表示式驗證IFSC代碼?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

熱門話題

我們通常會接收到政府或其他機構發送的PDF文件,有些文件有數位簽章。驗證簽名後,我們會看到SignatureValid訊息和一個綠色勾號。如果簽章未驗證,會顯示有效性未知。驗證簽名很重要,以下看看如何在PDF中進行驗證。如何在PDF中驗證簽名驗證PDF格式的簽名使其更可信,文件更容易被接受。您可以透過以下方式驗證PDF文件中的簽名。在AdobeReader中開啟PDF右鍵點選簽名,然後選擇顯示簽名屬性點選顯示簽署者憑證按鈕從「信任」標籤將簽名新增至「受信任的憑證」清單中點選驗證簽名以完成驗證讓

1.打開微信進入後,點選搜尋圖標,輸入微信團隊,點選下方的服務進入。 2、進入後,點選左下方的自助工具的選項。 3、點選後,在上方的選項內,點選解封/申訴輔助驗證的選項。

PHP8是PHP的最新版本,為程式設計師帶來了更多的便利性和功能。這個版本特別關注安全性和效能,其中一個值得注意的新功能是增加了驗證和簽章功能。在本文中,我們將深入了解這些新的功能及其用途。驗證和簽名是電腦科學中非常重要的安全概念。它們通常用於確保傳輸的數據是完整和真實的。在處理線上交易和敏感資訊時,驗證和簽名變得尤為重要,因為如果有人能夠篡改數據,可能會對

PHP正規表示式驗證:數位格式偵測在編寫PHP程式時,經常需要對使用者輸入的資料進行驗證,其中一個常見的驗證是檢查資料是否符合指定的數字格式。在PHP中,可以使用正規表示式來實現這種驗證。本文將介紹如何使用PHP正規表示式來驗證數字格式,並提供具體的程式碼範例。首先,讓我們來看看常見的數字格式驗證要求:整數:只包含數字0-9,可以以正負號開頭,不包含小數點。浮點

若要使用正規表示式在Golang中驗證電子郵件地址,請執行下列步驟:使用regexp.MustCompile建立正規表示式模式,以符合有效的電子郵件地址格式。使用MatchString函數檢查字串是否與模式相符。此模式涵蓋了大多數有效的電子郵件地址格式,包括:局部使用者名稱可以包含字母、數字和特殊字元:!.#$%&'*+/=?^_{|}~-`網域至少包含一個字母,後面可以跟字母、數字或連字符頂級域名(TLD)不能超過63個字符長

在Go中,可以使用正規表示式比對時間戳記:編譯正規表示式字串,例如用於匹配ISO8601時間戳記的表達式:^\d{4}-\d{2}-\d{2}T \d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-][0-9]{2}:[0-9]{2})$ 。使用regexp.MatchString函數檢查字串是否與正規表示式相符。

Go語言作為一門現代化的程式語言,提供了強大的正規表示式和字串處理功能,使得開發者能夠更有效率地處理字串資料。掌握Go語言的正規表示式和字串處理,對於開發者來說是非常重要的。本文將詳細介紹Go語言中正規表示式的基本概念和用法,以及如何使用Go語言處理字串。一、正規表示式正規表示式是用來描述字串模式的工具,能夠方便地實現字串的匹配、尋找和替換等操

PHP正規表示式:精確匹配與排除模糊包含正規表示式是一種強大的文字匹配工具,能夠幫助程式設計師在處理文字時進行高效的搜尋、替換和篩選。在PHP中,正規表示式也被廣泛應用於字串處理和資料匹配。本文將重點介紹在PHP中如何進行精確配對和排除模糊包含的操作,同時結合具體的程式碼範例進行說明。精確匹配精確匹配意味著只匹配符合完全條件的字串,不匹配任何變種或包含額外字
