+ 1
Email Id validation in C++
write a program in c++ to check email id is valid or not ?
7 Answers
+ 7
bool Email(string email)
{
const regex pattern("(\\w+)(\\.|_)?(\\w*)@(\\w+)(\\.(\\w+))+");
return regex_match(email,pattern);
}
Explanation:
The \w group matches any character in any case any number of times. Then the \.|_ matches if a dot or underscore is present 0 or 1 times. Then \w again match n characters. Then @ matches the @ in the email. Then we again check for n characters and a '.' and a word after it, which must be present atleast one or more times.
For more info, see the python tutorial > regex expressions
Eg of emails that are matched :
abc@gmail.com
myyahooacc@yahoo.co.in
my_email@hotmail.ca
Etc.
You need to include <regex> header for this.
+ 6
@Rema
#include<iostream>
#include<regex>
using namespace std;
bool Email(string email)
{
const regex pattern("(\\w+)(\\.|_)?(\\w*)@(\\w+)(\\.(\\w+))+");
return regex_match(email,pattern);
}
int main()
{
cout<<"Enter any E-Mail ID - "<<endl;
string str; getline(cin,str);
if(EMail(str))
cout<<"Yes, your E-Mail ID is valid!"<<endl;
else
cout<<"Sorry, Your E-Mail ID isn't valid."<<endl;
return 0;
}
+ 1
You need to looking for "@", ".", and other especial caracters. You can use and array of chars with dinamic memory to get the string, and looking for with a for.
0
Why don't you do it yourself?
0
do{
email.checkValidation();
}while(email!=valid);
DONE
0
Wow... good you can copy and paste it.
0
Iām sorry but I couldnāt understand, please anyone write the code for me :( .