-
Notifications
You must be signed in to change notification settings - Fork 25
/
validate.lua
35 lines (32 loc) · 957 Bytes
/
validate.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
local type = type
function check_username(s)
if type(s) ~= "string" then
return false, "Username must be a string"
elseif s:len() > 12 or s:len() < 3 then
return false, "Username must be 3-12 characters"
else
local match = s:match("[a-zA-Z0-9]+")
if match == nil or match:len() ~= s:len() then
return false, "Username can only contain letters and numbers"
end
end
return true
end
function check_email(s)
if type(s) ~= "string" then
return false, "Email must be a string"
elseif s:len() > 100 or s:len() < 3 then
return false, "Email must be 3-100 characters"
elseif not s:match(".+@.+") then
return false, "Email must be stuff, then @, then more stuff"
end
return true
end
function check_password(s)
if type(s) ~= "string" then
return false, "Password must be a string"
elseif s:len() < 6 or s:len() > 100 then
return false, "Password must be 6-100 characters"
end
return true
end