aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authord9k <d9k@ya.ru>2018-05-04 23:09:24 +0300
committerd9k <d9k@ya.ru>2018-05-04 23:09:24 +0300
commitf34865745e30cadf458d8a13600869c77bcc3839 (patch)
tree225e9ccc2d881995e8d299093e941ec34a13b970
parent56b5189cb9f188a1064296fea3d239a1ae8b7f79 (diff)
downloadvalua-f34865745e30cadf458d8a13600869c77bcc3839.tar.gz
valua-f34865745e30cadf458d8a13600869c77bcc3839.tar.bz2
valua-f34865745e30cadf458d8a13600869c77bcc3839.zip
README: documentation for optional() validator construction method. Added test when optional() is not last method in chain.
-rw-r--r--README.md33
-rw-r--r--valua-test.lua1
2 files changed, 18 insertions, 16 deletions
diff --git a/README.md b/README.md
index 25a44c6..578cd11 100644
--- a/README.md
+++ b/README.md
@@ -29,43 +29,44 @@ reusable_validation("test!") -- true
#### Current validation functions
- * alnum() -
+ * alnum() -
Checks if string is alphanumeric.
- * boolean() -
+ * boolean() -
Checks if value is a boolean.
- * compare(another_value) -
+ * compare(another_value) -
Checks if value is equal to another value.
- * contains(substr) -
+ * contains(substr) -
Checks if a string contains a substring.
- * date() or date(format) -
+ * date() or date(format) -
Checks if a string is a valid date. Default format is UK (dd/mm/yyyy). Also checks for US and ISO formats.
- * email() -
+ * email() -
Checks if a string is a valid email address.
- * empty() -
+ * empty() -
Checks if a value is empty.
- * integer() -
+ * integer() -
Checks if a number is an integer;
- * in_list(list) -
+ * in_list(list) -
Checks if a value is inside an array.
* len(min,max) -
Checks if a string's length is between min and max.
* match(pattern) -
Checks if a string matches a given pattern.
- * max(n) -
+ * max(n) -
Checks if a number is equal or less than n.
- * min(n) -
+ * min(n) -
Checks if a number is equal or greater than n.
- * not_empty() -
+ * not_empty() -
Checks if a value is not empty.
- * no_white() -
+ * no_white() -
Checks if a string contains no white spaces.
- * number() -
+ * number() -
Checks if a value is a number.
- * string() -
+ * string() -
Checks if a value is a string.
* type(t) -
Checks if a value is of type t.
-
+ * optional(t) -
+If value is `nil` it would be accepted. If it's not `nil` it would be processed with other chained validation functions as usually done.
Copyright (c) 2014 Etiene Dalcol
diff --git a/valua-test.lua b/valua-test.lua
index fa0cfb9..3d78740 100644
--- a/valua-test.lua
+++ b/valua-test.lua
@@ -64,6 +64,7 @@ local tests = {
{v:new().no_white(), {1,false, 2,true}},
{v:new().datetime(), {19,true, 9,false}},
{v:new().number().min(45).optional(), {2,false, 6,false, 7,true, 4,true}},
+ {v:new().number().optional().min(45), {2,false, 6,false, 7,true, 4,true}},
{v:new().string().optional(), {14,false, 1,true, 4,true}},
}