Checking for valid fieldname

Post Reply
Marc Vanzegbroeck
Posts: 1102
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium
Contact:

Checking for valid fieldname

Post by Marc Vanzegbroeck »

Hi,

My program import data from an other system. These files include a parameter and info about this parameter. When I import it I create a fieldname with the same name as the parameter from the imported file. Till now I had no problem but a client wanted to import a file that contains wrong info. My program wanted to create a fieldname containing '*' and other strange characters. Is there a way to chech if a fieldname is correct?

Thanks,
Marc
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Post by Otto »

Maybe this func could help you.
Regards,
Otto

func f_isOK(cTest)
local cReturn:=""
local i:=0

FOR I := 1 TO len(cTestl)

IF ASC(substr(cTest,i,1)) >= 33 .and. ASC(substr(cTest,i,1)) <= 90
cReturn:=cReturn+substr(cTest,i,1)

elseif ASC(substr(cTest,i,1)) >= 97 .and. ASC(substr(cTest,i,1)) <= 122
cReturn:=cReturn+substr(cTest,i,1)

elseif ...

ENDIF
NEXT
return (cReturn)
demont frank
Posts: 167
Joined: Thu Mar 22, 2007 11:24 am

Post by demont frank »

Using charonly :

Code: Select all

LOCAL CharAllowed := "" , i , lOk
FOR i := 65 TO 90
  CharAllowed += CHR(i) + CHR(i+32)
NEXT
// Are numbers allowed in fieldnames ? If yes add the range 48-57
lOk := ( LEN(CharOnly(CharAllowed,cString) == LEN(cString) )
RETURN lOk   // Or CharOnly(CharAllowed,cString) 
Marc Vanzegbroeck
Posts: 1102
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium
Contact:

Post by Marc Vanzegbroeck »

Otto, Frank,

Thanks for the info. I will try it.

Marc
Post Reply