How to validate PAN Card number using Regular Expression | C ++ program to validate the PAN Card number using Regular Expression ; Function to validate the PAN Card number . ; Regex to check valid PAN Card number . ; If the PAN Card number is empty return false ; Return true if the PAN Card number matched the ReGex ; Driver Code ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 : ; Test Case 5 :
#include <iostream> NEW_LINE #include <regex> NEW_LINE using namespace std ; bool isValidPanCardNo ( string panCardNo ) { const regex pattern ( " [ A - Z ] { 5 } [ 0-9 ] { 4 } [ A - Z ] { 1 } " ) ; if ( panCardNo . empty ( ) ) { return false ; } if ( regex_match ( panCardNo , pattern ) ) { return true ; } else { return false ; } } int main ( ) { string str1 = " BNZAA2318J " ; cout << isValidPanCardNo ( str1 ) << endl ; string str2 = "23ZAABN18J " ; cout << isValidPanCardNo ( str2 ) << endl ; string str3 = " BNZAA2318JM " ; cout << isValidPanCardNo ( str3 ) << endl ; string str4 = " BNZAA23184" ; cout << isValidPanCardNo ( str4 ) << endl ; string str5 = " BNZAA ▁ 23184" ; cout << isValidPanCardNo ( str5 ) << endl ; return 0 ; }