Created
April 26, 2015 13:15
-
-
Save krysseltillada/6162664fb297a8327fc7 to your computer and use it in GitHub Desktop.
email address validator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <iostream> | |
using namespace std; | |
bool chck_email(string); | |
int main() | |
{ | |
string str; | |
cout << "enter an email address: "; | |
getline(cin, str); | |
if(chck_email(str)) | |
cout << "this is an email address" << endl; | |
else | |
cout << "this is not an email address" << endl; | |
return 0; | |
} | |
bool chck_email(string chck) | |
{ | |
string getdomain; | |
int countstring1 = 0, countstring2 = 0, countstring3 = 0; | |
for(int c = 0; c < chck.length(); c++) | |
{ | |
if(chck.at(c) == '@'){ | |
countstring1++; | |
countstring3++; | |
for(; countstring1 < chck.length(); countstring1++){ | |
if(chck.at(countstring1) == '.'){ | |
countstring2++; | |
countstring2 = countstring2 + countstring3; | |
getdomain = chck.substr(countstring2, int(chck.length())); | |
if(getdomain == "com" || getdomain == "org" || getdomain == "net" || getdomain == "int" || getdomain == "edu" || getdomain == "gov" || getdomain == "mil"){ | |
return true; | |
} | |
else{ | |
return false; | |
} | |
} | |
else{ | |
countstring2++; | |
continue; | |
} | |
} | |
} | |
else{ | |
countstring1++; | |
countstring3++; | |
continue; | |
} | |
} | |
return false; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment