+ 1

Email Id validation in C++

write a program in c++ to check email id is valid or not ?

26th Nov 2017, 7:10 PM
Sarang Kamble
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.
27th Nov 2017, 3:17 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 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; }
8th Dec 2017, 7:56 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 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.
27th Nov 2017, 2:46 AM
Iago
Iago - avatar
0
Why don't you do it yourself?
26th Nov 2017, 7:45 PM
Timon Paßlick
0
do{ email.checkValidation(); }while(email!=valid); DONE
26th Nov 2017, 8:10 PM
Dmitrii
Dmitrii - avatar
0
Wow... good you can copy and paste it.
30th Nov 2017, 6:03 AM
Timon Paßlick
0
I’m sorry but I couldn’t understand, please anyone write the code for me :( .
7th Dec 2017, 11:27 PM
Rema