This is what I have so far. This isn't working and this isn't even close to working. I'm not that experienced at C++ so I was hoping that someone would help me please. The assignment is basically to write a code to validate an email address to see what characters are allowed and what characters aren't allowed. Please help in anyway possible.
Thank you.
// reading a text file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int spc_email_isvalid(const char *address) {
int count = 0;
const char *c, *domain;
static char *specialchars = "()<>@,;:\\\"[]";
// validate the name portion (name@domain)
for (c = address; *c; c++) {
if (*c == '\"' && (c == address || *(c - 1) == '.' || *(c - 1) ==
'\"')) {
while (*++c) {
if (*c == '\"') break;
if (*c == '\\' && (*++c == ' ')) continue;
if (*c < ' ' || *c >= 127) return 0;
}
if (!*c++) return 0;
if (*c == '@') break;
if (*c != '.') return 0;
continue;
}
if (*c == '@') break;
if (*c <= ' ' || *c >= 127) return 0;
if (strchr(specialchars, *c)) return 0;
}
if (c == address || *(c - 1) == '.') return 0;
// validate the domain portion (name@domain)
if (!*(domain = ++c)) return 0;
do {
if (*c == '.') {
if (c == domain || *(c - 1) == '.') return 0;
count++;
}
if (*c <= ' ' || *c &>= 127) return 0;
if (strchr(specialchars, *c)) return 0;
} while (*++c);
This is what I have so far. This isn't working and this isn't even close to working. I'm not that experienced at C++ so I was hoping that someone would help me please. The assignment is basically to write a code to validate an email address to see what characters are allowed and what characters aren't allowed. Please help in anyway possible.
Thank you.
If you're using VS2008, you can download the feature pack which includes TR1 regular expressions. Which means you can pretty much use any email-validation regular expression found on the web (there are plenty) and use it in C++.
Bookmarks