Page 1 of 1

New function For check email

Posted: Fri Mar 18, 2016 4:52 pm
by HATHAL
Hello
Now verify the e-mail before saving in the database.
function returns zero if the mail is wrong or if one is true.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// check email
// check_em.prg
#include "FiveWin.ch"
func main()
local e_mail_ok="LIVESYSTEM_NET@HOTMAIL.COM"
local e_mail_error="LIVESYSTEM_NET#HOTMAIL.COM"
? C_CHECK_EMAIL(ALLTRIM(e_mail_ok))
? C_CHECK_EMAIL(ALLTRIM(e_mail_error))
return .t.
// ***********************************************
#pragma BEGINDUMP
#include "windows.h"
#include "hbapiitm.h"
#include "hbvm.h"
#include "hbstack.h"
#include "item.api"
#include "hbpcode.h"
#include "hbvmpub.h"
// --------- function check email --------------
#include <string.h>
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);
}
// ------------------------
//------------- function check email -----------
HB_FUNC ( C_CHECK_EMAIL )
{
int RET_N=0;
char far *URL_EMAIL;
URL_EMAIL = hb_parc(1);
RET_N=spc_email_isvalid((const char *)URL_EMAIL);
hb_retni(RET_N);
}
// *************************
#pragma ENDDUMP
++++++++++++++++++++++++
greetings to you all.
Hathal.
:D

Re: New function For check email

Posted: Fri Mar 18, 2016 6:00 pm
by Antonio Linares
Hathal,

Thanks! :-)

Re: New function For check email

Posted: Fri Mar 18, 2016 6:48 pm
by Armando
Hathal:

Nice job and very usefull.

Regards

Re: New function For check email

Posted: Fri Apr 15, 2016 3:14 pm
by karinha

Code: Select all

check_em.c:
Warning W8075 check_em.prg 80: Suspicious pointer conversion in function HB_FUN_C_CHECK_EMAIL

Warning W8004 check_em.prg 78: 'RET_N' is assigned a value that is never used in function HB_FUN_C_CHECK_EMAIL