From b6aa0fceec7ae22d54985043a2d216e28ce941ac Mon Sep 17 00:00:00 2001 From: Etiene Date: Thu, 13 Mar 2014 09:44:34 +0000 Subject: New email pattern match --- valua-test.lua | 8 +++++--- valua.lua | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/valua-test.lua b/valua-test.lua index 0291aaf..35dc247 100644 --- a/valua-test.lua +++ b/valua-test.lua @@ -7,7 +7,7 @@ local function check(val_test, test_value, expected, n) if res == expected then msg = msg.. "succeeded" else - msg = msg.. "FAILED" + msg = msg.. " \27[31m FAILED \27[0m" end msg = msg.." on '"..(tostring(test_value)).."'. Expected: "..tostring(expected)..", result: "..tostring(res)..". " print(msg) @@ -30,7 +30,9 @@ local test_values = { 'asd123', 5.7, {}, - {3,46} + {3,46}, + "", + "test-123_maria.2@newdomain.wow.movie" } local tests = { @@ -47,7 +49,7 @@ local tests = { {v:new().number().max(1009),{7,false,6,true}}, {v:new().date(),{9,false,10,false,11,true,8,true}}, {v:new().date('us'),{8,false,9,true}}, - {v:new().email(),{13,false,12,true}}, + {v:new().email(),{13,false,12,true,17,false,18,true}}, {v:new().in_list({"hey",42}),{12,false,6,true,2,true}}, {v:new().match("^%d+%p%d+%p%d%d%d%d$"),{1,false,8,true}}, {v:new().alnum(),{8,false,13,true}}, diff --git a/valua.lua b/valua.lua index 8ffdccf..dad5a65 100644 --- a/valua.lua +++ b/valua.lua @@ -93,7 +93,7 @@ function valua._compare(value,another_value) end function valua._email(value) - if not value:match("[A-Za-z0-9%.%%%+%-]+@[A-Za-z0-9%.%%%+%-]+%.%w%w+") then + if not value:match("^[%w+%.%-_]+@[%w+%.%-_]+%.%a%a+$") then return false, "is not a valid email address" end return true -- cgit v1.2.3-54-g00ecf