How to validate Indian driving license number using Regular Expression | C ++ program to validate the Indian driving license number using Regular Expression ; Function to validate the Indian driving license number ; Regex to check valid Indian driving license number ; If the Indian driving license number is empty return false ; Return true if the Indian driving license 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 isValidLicenseNo ( string str ) { const regex pattern ( " ^ ( ( [ A - Z ] { 2 } [ 0-9 ] { 2 } ) ( ▁ " " ) | ( [ A - Z ] { 2 } - [0-9 ] { 2 } ) ) " " ( (19 ▁ 20 ) [ 0 - " "9 ] [ 0-9 ] ) [0-9 ] { 7 } $ " ) ; if ( str . empty ( ) ) { return false ; } if ( regex_match ( str , pattern ) ) { return true ; } else { return false ; } } int main ( ) { string str1 = " HR - 0619850034761" ; cout << isValidLicenseNo ( str1 ) << endl ; string str2 = " UP14 ▁ 20160034761" ; cout << isValidLicenseNo ( str2 ) << endl ; string str3 = "12HR - 37200602347" ; cout << isValidLicenseNo ( str3 ) << endl ; string str4 = " MH27 ▁ 30123476102" ; cout << isValidLicenseNo ( str4 ) << endl ; string str5 = " GJ - 2420180" ; cout << isValidLicenseNo ( str5 ) << endl ; return 0 ; }