Help with Email Validation
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Help with Email Validation

  1. #1
    Join Date
    Sep 2009
    Posts
    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 == '\"' &amp;&amp; (c == address || *(c - 1) == '.' || *(c - 1) ==
    '\"')) {
    while (*++c) {
    if (*c == '\"') break;
    if (*c == '\\' &amp;&amp; (*++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);
    }

    */

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,090

    Re: Help with Email Validation

    Code tags
    Indentation
    Single statement per line

    That code is unreadable as posted

  3. #3
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: Help with Email Validation

    Checking what is allowed is easier then checking what isn't allowed.

  4. #4
    Join Date
    Nov 2001
    Posts
    251

    Re: Help with Email Validation

    Quote Originally Posted by help123456789 View Post
    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center