New function For check email

Post Reply
User avatar
HATHAL
Posts: 77
Joined: Tue Nov 15, 2005 3:38 pm
Location: The Kingdom Saudi Arabia -Riyadh
Contact:

New function For check email

Post 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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: New function For check email

Post by Antonio Linares »

Hathal,

Thanks! :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Armando
Posts: 2479
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México
Contact:

Re: New function For check email

Post by Armando »

Hathal:

Nice job and very usefull.

Regards
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
karinha
Posts: 4882
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: New function For check email

Post 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
 
João Santos - São Paulo - Brasil
Post Reply