Validating text box

Rated 4.90/5 based on 868 customer reviews

It returns a Dialog Result to detect wheather the OK or the Cancel button has been clicked.

validating text box-88

validating text box-16

validating text box-37

validating text box-73

In this example I use simple class named Input Box with static method Show (to be similar to Message Box. It has overloaded static method Show which takes following paramaters: a dialog title, a prompt text, a default value and optionally a validation delegate.

There are 2 code paths for validation failure, and in each case we provide the user with an appropriate error message.

The error provider simply takes a control and a message in the Set Error method and does the rest of the work for you!

What I gave above, after setting the Max/Min should prevent the user from entering any value other then 0-9, you dont even need the validator with the script but, the validator is a backup incase the user turns off scripting, atleast then you have server side validation.

Dont forget to change your max and min of the validator to be what you wnat it to be something like Max 10 Min .01 or whatever it is you need the text to be within.

Leave a Reply