JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Custom Validators

As we've seen, there are different types of validators and they do different things, but sometimes they just can't check your data in as specific a way as you might like. For example—what if you wanted to find out whether a number was odd or even? You can't use a range or comparison validator for that. However, you can use a custom validator.

With a custom validator, you set the ClientValidationFunction property to the name of a script function, such as a JavaScript or VBScript function (VBScript is a Microsoft scripting language that supports a tiny subset of Visual Basic), both of which are supported in the Internet Explorer. This function will be passed two arguments, source, giving the source control to validate, and arguments, which holds the data to validate as arguments.Value. If you validate the data, you set arguments.IsValid to True, but to False otherwise.

There's a custom validator in the ValidationControls example on the CD-ROM that you see in Figure 18.2, next to the fifth text box. This validator will check the amount of tuition people enter into that text box to make sure that they're going to pay enough. Using custom validators is perhaps the most powerful way to use validators that there is—beyond the simple range checking and field checking validators, custom validators let you write your own customization code.

Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor