How to validate GST ( Goods and Services Tax ) number using Regular Expression | C ++ program to validate the GST ( Goods and Services Tax ) number using Regular Expression ; Function to validate the GST ( Goods and Services Tax ) number ; Regex to check valid GST ( Goods and Services Tax ) number ; If the GST ( Goods and Services Tax ) number is empty return false ; Return true if the GST 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 isValidGSTNo ( string str ) { const regex pattern ( " ^ [ 0-9 ] { 2 } [ A - Z ] { 5 } " " [ 0-9 ] { 4 } [ A - Z ] { 1 } [ " "1-9A - Z ] { 1 } Z [ 0-9A - Z ] { 1 } $ " ) ; if ( str . empty ( ) ) { return false ; } if ( regex_match ( str , pattern ) ) { return true ; } else { return false ; } } int main ( ) { string str1 = "06BZAHM6385P6Z2" ; cout << isValidGSTNo ( str1 ) << endl ; string str2 = "06BZAF67" ; cout << isValidGSTNo ( str2 ) << endl ; string str3 = " AZBZAHM6385P6Z2" ; cout << isValidGSTNo ( str3 ) << endl ; string str4 = "06BZ63AHM85P6Z2" ; cout << isValidGSTNo ( str4 ) << endl ; string str5 = "06BZAHM6385P6F2" ; cout << isValidGSTNo ( str5 ) << endl ; return 0 ; }