Code Block
*------------------------------------------------------------------------------
*- Program..: my_validate
*------------------------------------------------------------------------------
*- Synopsis...: The test program below was written for validating numeric data.
*- The code can easily be altered to validate whatever conditions
*- or criteria desired.
*------------------------------------------------------------------------------
*- Passed:
*- Variables..: None
*- Parameters.: None
*- Return Value: None
*------------------------------------------------------------------------------
lc_test = INPUTBOX("Please enter something to test.")
lc_test = CHRTRAN(lc_test, ", ", "")
*-- to remove commas from numbers in a text field in a table, uncomment below
*!* REPLACE <fieldname> WITH CHRTRAN(fieldname, ",", "") ALL
ll_badNumber = .f.
ln_countTotal = LEN(lc_test)
FOR ln_count = 1 TO ln_countTotal
*-- In the IF statement below, you can specify the criteria for what is not allowed
*-- Everything not part of the "not allowed criteria" is considered correct
IF NOT INLIST(SUBSTR(lc_test, ln_count, 1), ;
"-", ;
"0", ;
"1", ;
"2", ;
"3", ;
"4", ;
"5", ;
"6", ;
"7", ;
"8", ;
"9", ;
".")
ll_badNumber = .t.
EXIT
ENDIF
ENDFOR
IF NOT ll_badNumber
*-- This is to check if the minus sign ("-") occurs only once, and if so,
*-- is it the first character
ln_minus = OCCURS("-", lc_test)
IF ln_minus > 1
ll_badNumber = .t.
ELSE
IF ln_minus = 1 AND LEFT(lc_test,1) <> "-"
ll_badNumber = .t.
ENDIF
ENDIF
IF OCCURS(".", lc_test) > 1
ll_badNumber = .t.
ENDIF
ENDIF
IF ll_badNumber THEN
MESSAGEBOX(lc_test + " is a bad number!")
ELSE && lc_test is a good number, does not contain any of the wrong criteria
MESSAGEBOX(lc_test + " is a good number!")
ENDIF
RETURN