How to validate CVV number using Regular Expression | C ++ program to validate the CVV ( Card Verification Value ) number using Regular Expression ; Function to validate the CVV ( Card Verification Value ) number ; Regex to check valid CVV ( Card Verification Value ) number ; If the CVV ( Card Verification Value ) number is empty return false ; Return true if the CVV ( Card Verification Value ) number matched the ReGex ; Driver Code ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 :
#include <iostream> NEW_LINE #include <regex> NEW_LINE using namespace std ; bool isValidCVVNumber ( string str ) { const regex pattern ( " ^ [ 0-9 ] { 3,4 } $ " ) ; if ( str . empty ( ) ) { return false ; } if ( regex_match ( str , pattern ) ) { return true ; } else { return false ; } } int main ( ) { string str1 = "561" ; cout << isValidCVVNumber ( str1 ) << endl ; string str2 = "5061" ; cout << isValidCVVNumber ( str2 ) << endl ; string str3 = "50614" ; cout << isValidCVVNumber ( str3 ) << endl ; string str4 = "5a # 1" ; cout << isValidCVVNumber ( str4 ) << endl ; return 0 ; }