Skip to content

Commit

Permalink
New email pattern match
Browse files Browse the repository at this point in the history
  • Loading branch information
Etiene committed Mar 13, 2014
1 parent 5b00ea4 commit b6aa0fc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions valua-test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -30,7 +30,9 @@ local test_values = {
'asd123',
5.7,
{},
{3,46}
{3,46},
"<script>alert('[email protected] XSS');</script>",
"[email protected]"
}

local tests = {
Expand All @@ -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}},
Expand Down
2 changes: 1 addition & 1 deletion valua.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b6aa0fc

Please sign in to comment.