How to validate pin code of India using Regular Expression | C ++ program to validate the pin code of India using Regular Expression . ; Function to validate the pin code of India . ; Regex to check valid pin code of India . ; If the pin code is empty return false ; Return true if the pin code matched the ReGex ; Driver Code . ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 :
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isValidPinCode ( string pinCode ) { const regex pattern ( " ^ [ 1-9 ] { 1 } [ 0-9 ] { 2 } \\ s { 0,1 } [ 0-9 ] { 3 } $ " ) ; if ( pinCode . empty ( ) ) { return false ; } if ( regex_match ( pinCode , pattern ) ) { return true ; } else { return false ; } } void print ( bool n ) { if ( n == 0 ) { cout << " False " << endl ; } else { cout << " True " << endl ; } } int main ( ) { string num1 = "132103" ; cout << num1 + " : ▁ " ; print ( isValidPinCode ( num1 ) ) ; string num2 = "201 ▁ 305" ; cout << num2 + " : ▁ " ; print ( isValidPinCode ( num2 ) ) ; string num3 = "014205" ; cout << num3 + " : ▁ " ; print ( isValidPinCode ( num3 ) ) ; string num4 = "1473598" ; cout << num4 + " : ▁ " ; print ( isValidPinCode ( num4 ) ) ; return 0 ; }