teddybear
28th July 2009, 06:19
Hi there,

I am trying to write a function that scan a string for certain characters that are not allowed.

For example, the allowed character are A-Z, 1-9, comma, full stop, (, ), / and hyphen.

How can I write a fucntion that tell if characters not listed above is present.

Many thankssssss.

saumya
28th July 2009, 08:01
extern domain tcdsca cust
long i,j,length,
domain tcbool illegal
field.cust:
check.input:
check.char(cust)

if illegal = true then
message("illegal character not allowed.")
set.input.error("",e)
endif

functions:
function check.char(tcdsca cust)
{
length = len(cust)
illegal = false
for i = 1 to length
j = asc(cust(i;1))
if (j >=asc("A") and j <= asc("Z")) or
(j >=asc("a") and j <= asc("z")) or
(j >= asc("1") and j <= asc("9")) or
(asc(",") = j ) or
(asc(".") = j ) or
(asc("(") = j ) or
(asc(")") = j ) or
(asc("/") = j ) or
(asc("-") = j ) then
else
illegal = true

endif
endfor
}

teddybear
28th July 2009, 10:49
Thanks saumya

rameshchinnap
10th August 2009, 12:47
hi, use
string.scan()

examples:
double D

long L

string S(80)

long ret

ret = string.scan("string 123 456.78","%s %d %f",S,L,D)

| S contains "string", L contains 123, D contains 456.78

ret = string.scan("string|123|456.78","%s|%d|%f",S,L,D)

| S contains "string", L contains 123, D contains 456.78

BaanInOhio
10th August 2009, 18:05
in 'before.program' section, build a string with the good characters:

good.str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,/()"


... can add "& str$(nn)" for special characters (where 'nn' is the numeric representation of the character).


check each character by:

good = (pos(good.str, each.char) > 0) ? true : false

in a string parse or loop.

~Vamsi
24th August 2009, 20:08
Another alternative is to use regular expressions. See http://www.baanboard.com/programmers_manual_baanerp_help_functions_expressions_runtime_expr_compile for details.