Answers for "Check the below program to demonstrate how you can use the regex to validate incoming data."

C++
0

Check the below program to demonstrate how you can use the regex to validate incoming data.

#include <iostream>
#include <regex>
#include <string>
using namespace std;
  
int main()
{
    string input;
    regex integer_expr("(\\+|-)?[[:digit:]]+");
    //As long as the input is correct ask for another number
    while(true)
    {
        cout<<"Enter the input: ";
        cin>>input;
        if(!cin) break;
        //Exit when the user inputs q
        if(input=="q")
            break;
        if(regex_match(input,integer_expr))
            cout<<"Input is an integer"<<endl;
        else
        {cout<<"Invalid input : Not an integer"<<endl;}
    }
}
Posted by: Guest on August-19-2021

Code answers related to "Check the below program to demonstrate how you can use the regex to validate incoming data."

Browse Popular Code Answers by Language