From f34865745e30cadf458d8a13600869c77bcc3839 Mon Sep 17 00:00:00 2001 From: d9k Date: Fri, 4 May 2018 23:09:24 +0300 Subject: README: documentation for optional() validator construction method. Added test when optional() is not last method in chain. --- README.md | 33 +++++++++++++++++---------------- valua-test.lua | 1 + 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}}, } -- cgit v1.2.3-54-g00ecf