敏感字检测

敏感字检测

--判断是否存在特殊字符
-- @param{string}	str		名字字符串
-- return{boolean}
function _mt:filter_spec_chars(str)
	local have_special = false
	local k = 1
	local is_loop = true
	while is_loop do
		if k > #str then break end
		local c = string.byte(str,k)
		if not c then break end
		if c<192 then
			if (c>=48 and c<=57) or (c>= 65 and c<=90) or (c>=97 and c<=122) then
				-- table.insert(ss, string.char(c))
			else
				have_special = true
				is_loop = false
			end
			k = k + 1
		elseif c<224 then
			have_special = true
			is_loop = false
			k = k + 2
		elseif c<240 then
			if c>=228 and c<=233 then
				local c1 = string.byte(str,k+1)
				local c2 = string.byte(str,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>=a3 and c2<=a4 then
						-- table.insert(ss, string.char(c,c1,c2))
					else
						have_special = true
						is_loop = false
					end
				end
			end
			k = k + 3
		elseif c<248 then
			have_special = true
			is_loop = false
			k = k + 4
		elseif c<252 then
			have_special = true
			is_loop = false
			k = k + 5
		elseif c<254 then
			have_special = true
			is_loop = false
			k = k + 6
		end
	end
	return have_special
end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值