Search code examples
visual-c++email-validation

return value not correct


Am using this function

int spc_email_isvalid(const char *address) {


int        count = 0;
const char *c, *domain;
static char *rfc822_specials = "()<>@,;:\\\"[]";

/* first we 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(rfc822_specials, *c)) return 0;
}
if (c == address || *(c - 1) == '.') return 0;

/* next we 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(rfc822_specials, *c)) return 0;
} while (*++c);

return (count >= 1);
}

when i all the function AfxMessageBox(spc_email_isvalid("[email protected]")); it returns null

how to get the value o or 1 based on the email id


Solution

  • AfxMessageBox needs LPCTSTR as the first parameter:

    CString str;     
    str.Format( _T("%d"), spc_email_isvalid("[email protected]")); 
    
    AfxMessageBox( str, MB_OK | MB_ICONINFORMATION );