Prev | Current Page 761 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

)+[a-z]{2,})$???,
options : ???i??™,
message : ???Invalid email format??? });
FormValidator.registerRule(???loweralphanum???, PatternRule,
{ pattern : ???^[a-z0-9]+$???,
message : ???Use only lower-case, alpha-numeric characters??? });
FormValidator.registerRule(???range???, RangeRule);
FormValidator.registerRule(???compare???, CompareRule);
FormValidator.applyToDocument();
}
}
In the example are defined the rules used in the above HTML page. More can be defined reusing the
available ValidationRule subclasses or by defining new classes, that satisfies specific validation
requirements.
ValidationRule is an abstract class to validate a single value. The validate() function performs the
check and returns true if the value has been validated successfully. If the validation fails, the reasons are
stored in the error field and used by the context to inform the user. The argument passed to
validate() is a string because this is the only data type possible when using values from a form. Note,
however, how the implementation of ValidationRule is independent from the FormValidator class
and it is possible to use it and its subclasses in other programming contexts like Neko or Flash.


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