How to validate IFSC Code using Regular Expression | Python3 program to validate IFSC ( Indian Financial System ) Code using regular expression ; Function to validate IFSC ( Indian Financial System ) Code using regular expression . ; Regex to check valid IFSC Code . ; Compile the ReGex ; If the string is empty return false ; Return if the string matched the ReGex ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 :
import re NEW_LINE def isValidIFSCode ( str ) : NEW_LINE INDENT regex = " ^ [ A - Z ] {4}0 [ A - Z0-9 ] { 6 } $ " NEW_LINE p = re . compile ( regex ) NEW_LINE if ( str == None ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( re . search ( p , str ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT str1 = " SBIN0125620" NEW_LINE print ( isValidIFSCode ( str1 ) ) NEW_LINE str2 = " SBIN0125" NEW_LINE print ( isValidIFSCode ( str2 ) ) NEW_LINE str3 = "1234SBIN012" NEW_LINE print ( isValidIFSCode ( str3 ) ) NEW_LINE str4 = " SBIN7125620" NEW_LINE print ( isValidIFSCode ( str4 ) ) NEW_LINE