07-09-2003, 06:18 AM
Write a bulletproof function to validate a user input string that must be:
* Strictly numeric, unsigned, no leading/trailing/embedded blanks.
* But may contain a decimal point. The number of decimal places that the number can contain is a specification for the input field.
* Cannot be null, obviously.
Example: FUNCTION NUMDECIMAL (userinput$, numdecimals)
Where:
userinput$ is the string input by the user.
numdecimals is a value of 0 to n, where n is the maximum number of decimal places allowed for this field. Numdecimals may be zero.
The NUMDECIMAL function returns -1 if valid field, or 0 if invalid.
Remember that users are likely to input all kinds of garbage, including numbers with 2 decimal points, like 123.45.67
P.S. Your posted programs will be tested.
*****
* Strictly numeric, unsigned, no leading/trailing/embedded blanks.
* But may contain a decimal point. The number of decimal places that the number can contain is a specification for the input field.
* Cannot be null, obviously.
Example: FUNCTION NUMDECIMAL (userinput$, numdecimals)
Where:
userinput$ is the string input by the user.
numdecimals is a value of 0 to n, where n is the maximum number of decimal places allowed for this field. Numdecimals may be zero.
The NUMDECIMAL function returns -1 if valid field, or 0 if invalid.
Remember that users are likely to input all kinds of garbage, including numbers with 2 decimal points, like 123.45.67
P.S. Your posted programs will be tested.
*****