From a567f68b811e0e9199f513eda7b3a1b35f47658f Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Thu, 26 Jun 2008 19:16:25 +0000 Subject: Rewrite of DNScache. git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@1262 ab2d0c66-481e-0410-8bed-d214d4d58bed --- lib/validator.lua | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'lib/validator.lua') 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) -- cgit v1.2.3