-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmail_id_validation.cpp
56 lines (52 loc) · 969 Bytes
/
Email_id_validation.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include<iostream>
#include<exception>
#include<string>
using namespace std;
class StringException : public exception
{
pubic:
const char * what() const throw()
{
return "Invalid mail id";
}
};
bool checkEmail(string email)
{
bool val = False;
int symbolCount = 0, dotcount = 0;
for(int i = 0; i < email.length(); i++)
{
if(email[i] == '@')
symbolCount++;
else if(email[i] == '.')
dotCount++;
}
if(symbolCount == 1 && dotCount > 0)
val = true;
return val;
}
int main()
{
while(1)
{
bool val = True;
string email;
cout<<"Enter your Email Id :";
getline(cin, email);
cin.clear();
try
{
if(!checkEmail(email))
{
StringException ex;
throw ex;
}
break;
}
catch(exception& a)
{
cout<<a.what();
}
}
return 0;
}