PDA

View Full Version : Lorne’s two great input validation scripts


csd214
06-09-2004, 07:19 AM
Lorne has published two great functions. THANKS; this is to my taste. (I don’t want to clutter the Scripts and Example section, that’s why I use the General Forum.)

The validation scripts are a great example of how to “put functions into a table”. To everybody: Don’t miss them!

The function InputTest.Validate() was an “A-ha” experience. The test “if(String.TrimRight(strText, "1234567890-.") ~= "")” checks valid numeric input with five code lines. I have my own function Value() with more than 50 code lines (checking the ASCII value).

The only limit with Lorne’s script: It wouldn’t work outside US/Canada/UK. In countries using comma as the decimal point, you have to use the string "1234567890-,", but the decimal sign can be found in HKCU\Control Panel\International Value Name sDecimal or sMonDecimalSep (what’s the difference?). (Now Corey once more will say “Comma, Comma, Comma .. Chameleon”)

But I have a feeling that AMS already knows that I have the comma as decimal point. The help doc has this info about the input mask:

Decimal placeholder. (Special literal.) This will be replaced by the character specified as the decimal placeholder in the user's international settings. To force a period on all systems, use \. instead.

How can I wring the secret from AMS without reading the Registry?

But there’s another challenge with the input validation: How (when) to trigger the validation function? Of course you could have a Button.On Click event, but if the page has 8 input boxes, I should like to perform the validation immediately when the user has finished the input in each of the objects. “e_Key == 13” is one solution, but what to do when then user goes to Input2 by moving the mouse?

So far I have used this method:
* Enter/TAB to confirm input and move to next input object
* After the last input, force button Save/Candel to be pressed (or Enter in an invisible input object)
To take notice of mouse movement:
* An invisible image as a background object covering the input area, Image.On Leave actions starts the validation

My wish list has the item “Input.On Leave Event”. Could my wish be fulfilled in a future release?

Intrigued
06-09-2004, 09:41 AM
I appreciated the way the code was professional relayed myself.

I found the split lession approach to be an excellent way to help me ramp up to the next level with concerns to AMS coding techniques.

Lorne, thanks! (clap, clap)

Lorne
06-09-2004, 10:13 AM
Thanks guys. :)

Lorne has published two great functions. THANKS; this is to my taste. (I don’t want to clutter the Scripts and Example section, that’s why I use the General Forum.) Don't worry about cluttering up that section...you're free to post comments in any of those threads. (It's a moderated forum, so you can't start a new thread unless it gets approved by Desmond.) In general it's probably best to post comments right in the threads; it's a bit easier to keep track of everything that way, and in this case especially your comments would be valuable to anyone who wants to use the functions.

The function InputTest.Validate() was an “A-ha” experience. The test “if(String.TrimRight(strText, "1234567890-.") ~= "")” checks valid numeric input with five code lines. I have my own function Value() with more than 50 code lines (checking the ASCII value).If it makes you feel any better, those lines are still there...they're just inside the TrimRight() action. ;)

The only limit with Lorne’s script: It wouldn’t work outside US/Canada/UK. In countries using comma as the decimal point, you have to use the string "1234567890-,", but the decimal sign can be found in HKCU\Control Panel\International Value Name sDecimal or sMonDecimalSep (what’s the difference?). (Now Corey once more will say “Comma, Comma, Comma .. Chameleon”)(Mental image of the day: Boy George on a skateboard with a video camera.)

Good point about the internationalization. :) Another limitation of the script is that it doesn't check for the placement of the '-' (which is only valid as the first character) or the '.' (which is not valid as the last character), and doesn't check for more than one '.' in the string.

But I have a feeling that AMS already knows that I have the comma as decimal point. The help doc has this info about the input mask:

Decimal placeholder. (Special literal.) This will be replaced by the character specified as the decimal placeholder in the user's international settings. To force a period on all systems, use \. instead.

How can I wring the secret from AMS without reading the Registry?I haven't looked at the code, but I think that's just a feature of the C++ function that is being used to format the string.

But there’s another challenge with the input validation: How (when) to trigger the validation function? Of course you could have a Button.On Click event, but if the page has 8 input boxes, I should like to perform the validation immediately when the user has finished the input in each of the objects. “e_Key == 13” is one solution, but what to do when then user goes to Input2 by moving the mouse?

Generally it's best to perform validation when the user leaves the page or clicks a "Submit" button or something. Validating each field separately can seem intrusive, especially with 8 input objects.

If you really wanted to force them to fill in the fields in a specific order, you could validate the fields on each On Key event, and throw up a warning if they're not typing in the next empty field. But I think that could feel pretty heavy handed.

My wish list has the item “Input.On Leave Event”. Could my wish be fulfilled in a future release?You mean something like On Lose Focus? Or more like On Changed?

Edit: I submitted On Lose Focus/On Changed in our suggestions database. I also submitted a request for a _Decimal built-in variable.