Lua: 检测输入名字是否合法

--名字只包含:数字、字母、中文
function Panel:CheckName(_name)
    local ss = {}
    for k = 1, #_name do
        local c = string.byte(_name, k)
        if not c then break end
        if (c >= 48 and c <= 57) or (c >= 65 and c <=90) or (c >=97 and c <= 122) then
            ss[#ss + 1] = string.char(c)
        elseif c >= 228 and c <= 233 then
            local c1 = string.byte(_name, k + 1)
            local c2 = string.byte(_name, k + 2)
            if c1 and c2 then
                local a1, a2, a3, a4 = 128, 191, 128, 191
                if c == 228 then
                    a1 = 184
                elseif c = 233 then
                    a2, a4 = 190, c1 ~= 190 and 191 or 165
                end
                if c1 >= a1 and c1 <= a2 and c2 <= a4 then
                    k = k + 2
                    ss[#ss + 1] = string.char(c, c1, c2)
                end
            end
        end  
    end
    if #ss > 0 then
        local len = 0
        for k, v in pairs(ss) do
            len = len + #v
        end
        if #_name == len then
            return true
        else
            return false
        end
    else
        return false
    end
end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值