-
September 13th, 2009, 02:53 PM
#1
Help with Email Validation
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);
return (count >= 1);
}
*/
-
September 13th, 2009, 03:38 PM
#2
Re: Help with Email Validation
Code tags
Indentation
Single statement per line
That code is unreadable as posted
-
September 13th, 2009, 03:58 PM
#3
Re: Help with Email Validation
Checking what is allowed is easier then checking what isn't allowed.
-
September 13th, 2009, 06:16 PM
#4
Re: Help with Email Validation
Originally Posted by help123456789
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++.
http://www.microsoft.com/downloads/d...displaylang=en
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|