diff options
author | Ted Trask <ttrask01@yahoo.com> | 2008-06-26 19:16:25 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2008-06-26 19:16:25 +0000 |
commit | a567f68b811e0e9199f513eda7b3a1b35f47658f (patch) | |
tree | 80a6a648bd05a5495d499c257f3fe2923507e089 /lib/validator.lua | |
parent | 5dc852723da4fbf7b98bbcb0c8d258062d12684f (diff) | |
download | acf-core-a567f68b811e0e9199f513eda7b3a1b35f47658f.tar.bz2 acf-core-a567f68b811e0e9199f513eda7b3a1b35f47658f.tar.xz |
Rewrite of DNScache.
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@1262 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'lib/validator.lua')
-rwxr-xr-x | lib/validator.lua | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/validator.lua b/lib/validator.lua index d57ca5f..afea72c 100755 --- a/lib/validator.lua +++ b/lib/validator.lua @@ -108,6 +108,37 @@ function is_ipv4(ipv4) return true, validator.msg.err.Success[lang.Current] end +-- +-- This function validates a partial ipv4 address. +-- On success it returns 1 otherwise a negative value +-- +function is_partial_ipv4(ipv4) + local retval = false; + local nums = {}; + + -- Check to see if any invalid characters + if not ipv4 or not ipv4:match("^[%d%.]+$") then + return false, validator.msg.err.InvalidFormat[lang.Current] + end + + -- NC: Split the string into an array. separate with '.' (dots) + -- %d+ one or more digits + for num in ipv4:gmatch("%d+") do + nums[#nums+1] = num + -- too big? + if tonumber(num) > 255 then + return false, validator.msg.err.InvalidFormat[lang.Current] + end + end + + -- too many numbers + if #nums > 4 then + return false, validator.msg.err.InvalidFormat[lang.Current] + end + + return true, validator.msg.err.Success[lang.Current] +end + function is_mac(mac) local tmpmac = string.upper(mac) |