How to validate Indian Passport number using Regular Expression | C ++ program to validate the passport number using Regular Expression ; Function to validate the passport number ; Regex to check valid passport number ; If the passport number is empty return false ; Return true if the passport 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 isValidPassportNo ( string str ) { const regex pattern ( " ^ [ A - PR - WYa - pr - wy ] [1-9 ] " " \\ d \\ s ? \\ d { 4 } [ 1-9 ] $ " ) ; if ( str . empty ( ) ) { return false ; } if ( regex_match ( str , pattern ) ) { return true ; } else { return false ; } } int main ( ) { string str1 = " A21 ▁ 90457" ; cout << isValidPassportNo ( str1 ) << endl ; string str2 = " A0296457" ; cout << isValidPassportNo ( str2 ) << endl ; string str3 = " Q2096453" ; cout << isValidPassportNo ( str3 ) << endl ; string str4 = "12096457" ; cout << isValidPassportNo ( str4 ) << endl ; string str5 = " A209645704" ; cout << isValidPassportNo ( str5 ) << endl ; return 0 ; }