How to check Aadhar number is valid or not using Regular Expression | C ++ program to validate the Aadhar number using Regular Expression ; Function to validate the Aadhar number . ; Regex to check valid Aadhar number . ; If the Aadhar number is empty return false ; Return true if the Aadhar 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 isValidAadharNumber ( string str ) { const regex pattern ( " ^ [ 2-9 ] { 1 } [ 0-9 ] { 3 } \\ s [ 0-9 ] { 4 } \\ s [ 0-9 ] { 4 } $ " ) ; if ( str . empty ( ) ) { return false ; } if ( regex_match ( str , pattern ) ) { return true ; } else { return false ; } } int main ( ) { string str1 = "3675 ▁ 9834 ▁ 6015" ; cout << isValidAadharNumber ( str1 ) << endl ; string str2 = "4675 ▁ 9834 ▁ 6012 ▁ 8" ; cout << isValidAadharNumber ( str2 ) << endl ; string str3 = "0175 ▁ 9834 ▁ 6012" ; cout << isValidAadharNumber ( str3 ) << endl ; string str4 = "3675 ▁ 98AF ▁ 60#2" ; cout << isValidAadharNumber ( str4 ) << endl ; string str5 = "417598346012" ; cout << isValidAadharNumber ( str5 ) << endl ; return 0 ; }