New function For check email

New function For check email

Postby HATHAL » Fri Mar 18, 2016 4:52 pm

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
HATHAL
 
Posts: 77
Joined: Tue Nov 15, 2005 3:38 pm
Location: The Kingdom Saudi Arabia -Riyadh

Re: New function For check email

Postby Antonio Linares » Fri Mar 18, 2016 6:00 pm

Hathal,

Thanks! :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42094
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: New function For check email

Postby Armando » Fri Mar 18, 2016 6:48 pm

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
Armando
 
Posts: 3224
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

Re: New function For check email

Postby karinha » Fri Apr 15, 2016 3:14 pm

Code: Select all  Expand view

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 - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7814
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 33 guests