DRK 3 : TextField / DataValidation Example 1

I have been getting some requests for some examples of the components included on DRK 3, so I am going to try and post a bunch over the coming days.

The first example is a simple one showing how to validate user input using the TextField component and Data Validation library.


And here is the code:

[code]#include “com/macromedia/validation/DataValidation.as”//set the function to be called when isValid is called.//in this case it is the isDigit function from the DataValidation librarymyTextField_txf.setValidationFunction(“isDigit”, DataValidation);//set the default textfield icon to error.myTextField_txf.setIcon(“ftf_errorIcon”);//this is called when the validate button is pressedvalidate_btn.onRelease = function(){//call isValid to see if user input is valid.if(!myTextField_txf.isValid()){//if it is not, give an error and show the error icon.msgBox_txf.text = “Invalid Input. Please enter a number.”;myTextField_txf.showIcon(true);}else{//if it is valid, make sure the icon is off.msgBox_txf.text = “The input is a valid number”;myTextField_txf.showIcon(false);}}[/code]

You can view the on-line docs for the TextField component here.

You can find more information about the Flash UI Component Set 5 (which includes the TextField component) here.

You can find more information about DRK 3 here.

Post any requests for specific examples in the comments.

6 Responses to DRK 3 : TextField / DataValidation Example 1

  1. Phillip Kerman says:

    Try:2eDid I break it or what?Or, do you count ‘e’ like the natural log…?

  2. Okay, I’ll answer my own question. It appears to be a bug in Flash. Works fine in JavaScript (at least on IE Win).I don’t know how I found that one.Phillip

  3. maxxxx says:

    maybe 2e stands for “2 elevated”. anyway I think this should be invalid.

  4. Samuel Christie says:

    e is the exponent not natural log:2e3 = 20002e4 = 20000etc.2e is the same as 2e0 which should evaluate to 2This is not a bug. The e is not a method, function, or constant. It is actually a part of the number itself. Think of the following analogy:”Can’t” is a word though it stands for “Cannot” – should we rule it out because it’s a contraction – no, of course not. 2e10 is a whole lot easier to write than 20000000000, and simply should not be excluded from this validation.

  5. Samuel Christie says:

    To be a little more technical, e is actually not the exponent of the preceeding number. It is, as you can see from my example, the exponent of 10. As in the following:2e3 = 2*(10^3) = 2*1000 = 2000Just thought I’d correct myself.

  6. Anonymous says:

    Geeze. It doesn’t work if I enter “pi” either.