Prev | Current Page 760 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

It accepts a Form element as
argument for the constructor but probably the most obvious way to use the class is to invoke its static
applyToDocument() method that will create a new instance of FormValidator for each form that exists
in the page. The rules are registered using the static method registerRule() ; this way a registered rule
works for every instance of FormValidator . The registration requires a name (the one used in the
validation attribute), a class that is used to manage the rule, and an optional object that defines the
default parameters. A default parameter may be overridden by a parameter with the same name defined
in the HTML document.
import FormValidator;
import ValidationRule;
class Main
{
public static function main()
{
FormValidator.registerRule(???required???, RequiredRule);
(continued)
408
Part II: Server Side, JavaScript, and Flash: Oh My!
FormValidator.registerRule(???int???, NumericRule,
{ useint : true });
FormValidator.registerRule(???email???, PatternRule,
{ pattern : ???^([^@\\s]+)@((?:[-a-z0-9]+\\.


Pages:
748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772