Prev | Current Page 847 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

The FBool checks that the passed string can be converted to a Boolean value; accepted
values are true, false, 0, and 1 and they are case sensitive. The FEnum constructor accepts an array of
string values; if one in the list matches the tested value, the validation is passed. Finally, the FReg
constructor accepts a regular expression, an EReg object, to validate the string value.
The following rule adds two filters to the previous attribute example. The first FReg rule checks that
the name attribute is composed only of words that start with an uppercase character, separated by a
single space and it excludes any character not in the alphabet. The sex attribute is also validated against
the only two possible values f and m using an FEnum rule.
var schema = RNode(???person???, [
Att(???name???, FReg(~/^[A-Z][a-z]*( [A-Z][a-z]*)*$/)),
Att(???sex???, FEnum([???f???, ???m???]), ???m???)]);
See how the following XML fragments behave when validated against the preceding rule:
// passes
< person name=???John Doe??? sex=???m???/ >
// passes, too
< person name=???John Doe??? / >
// fails because the ???.


Pages:
835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859