]> gitweb.factorcode.org Git - factor.git/blob - basis/validators/validators-docs.factor
Merge branch 'master' into experimental (untested!)
[factor.git] / basis / validators / validators-docs.factor
1 USING: help.markup help.syntax io.streams.string quotations 
2 strings math regexp regexp.backend ;
3 IN: validators
4
5 HELP: v-captcha
6 { $values { "str" string } }
7 { $description "Throws a validation error if the string is non-empty. This is used to create bait fields for spam-bots to fill in." } ;
8
9 HELP: v-credit-card
10 { $values { "str" string } { "n" integer } }
11 { $description "If the credit card number passes the Luhn algorithm, converts it to an integer, otherwise throws an error." }
12 { $notes "See " { $url "http://en.wikipedia.org/wiki/Luhn_algorithm" } " for a description of this algorithm." } ;
13
14 HELP: v-default
15 { $values { "str" string } { "def" string } { "str/def" string } }
16 { $description "If the input string is not specified, replaces it with the default value." } ;
17
18 HELP: v-email
19 { $values { "str" string } }
20 { $description "Throws a validation error if the string is not a valid e-mail address, as determined by a regular expression." } ;
21
22 HELP: v-integer
23 { $values { "str" string } { "n" integer } }
24 { $description "Converts the string into an integer, throwing a validation error if the string is not a valid integer." } ;
25
26 HELP: v-min-length
27 { $values { "str" string } { "n" integer } }
28 { $description "Throws a validation error if the string is shorter than " { $snippet "n" } " characters." } ;
29
30 HELP: v-max-length
31 { $values { "str" string } { "n" integer } }
32 { $description "Throws a validation error if the string is longer than " { $snippet "n" } " characters." } ;
33
34 HELP: v-max-value
35 { $values { "x" integer } { "n" integer } }
36 { $description "Throws an error if " { $snippet "x" } " is larger than " { $snippet "n" } "." } ;
37
38 HELP: v-min-value
39 { $values { "x" integer } { "n" integer } }  
40 { $description "Throws an error if " { $snippet "x" } " is smaller than " { $snippet "n" } "." } ;
41
42 HELP: v-mode
43 { $values { "str" string } }
44 { $description "Throws an error if " { $snippet "str" } " is not a valid XMode mode name." } ;
45
46 HELP: v-number
47 { $values { "str" string } { "n" real } }
48 { $description "Converts the string into a real number, throwing a validation error if the string is not a valid real number." } ;
49
50 HELP: v-one-line
51 { $values { "str" string } }
52 { $description "Throws a validation error if the string contains line breaks." } ;
53
54 HELP: v-one-word
55 { $values { "str" string } }
56 { $description "Throws a validation error if the string contains word breaks." } ;
57
58 HELP: v-optional
59 { $values { "str" string } { "quot" quotation } { "result" string } }
60 { $description "If the string is non-empty, applies the quotation to the string, otherwise outputs the empty string." } ;
61
62 HELP: v-password
63 { $values { "str" string } }
64 { $description "A reasonable default validator for passwords." } ;
65
66 HELP: v-regexp
67 { $values { "str" string } { "what" string } { "regexp" regexp } }
68 { $description "Throws a validation error that " { $snippet "what" } " failed if the string does not match the regular expression." } ;
69
70 HELP: v-required
71 { $values { "str" string } }
72 { $description "Throws a validation error if the string is empty." } ;
73
74 HELP: v-url
75 { $values { "str" string } }
76 { $description "Throws an error if the string is not a valid URL, as determined by a regular expression." } ;
77
78 HELP: v-username
79 { $values { "str" string } }
80 { $description "A reasonable default validator for usernames." } ;
81
82 ARTICLE: "validators" "Form validators"
83 "The " { $vocab-link "validators" } " vocabulary provides a set of words which are intended to be used with the form validation functionality offered by " { $vocab-link "furnace.actions" } ". They can also be used independently of the web framework."
84 $nl
85 "Note that validators which take numbers must be preceded by " { $link v-integer } " or " { $link v-number } " if the original input is a string."
86 $nl
87 "Higher-order validators which require additional parameters:"
88 { $subsection v-default     }
89 { $subsection v-optional    }
90 { $subsection v-min-length  }
91 { $subsection v-max-length  }
92 { $subsection v-min-value   }
93 { $subsection v-max-value   }
94 { $subsection v-regexp      }
95 "Simple validators:"
96 { $subsection v-required    }
97 { $subsection v-number      }
98 { $subsection v-integer     }
99 { $subsection v-one-line    }
100 { $subsection v-one-word    }
101 { $subsection v-captcha     }
102 "More complex validators:"
103 { $subsection v-email       }
104 { $subsection v-url         }
105 { $subsection v-username    }
106 { $subsection v-password    }
107 { $subsection v-credit-card }
108 { $subsection v-mode        } ;
109
110 ABOUT: "validators"