【分享】cocostudio textfield输入内容区分字母或者数字

cocostudio textfield输入内容怎么区分字母或者数字?我的办法很简单,就是通过转换成ASSIC码比较。

local mystring = textfield:getStringValue()

function LoginUI:isNumberOrCharacter(mystring)
for i = 1,#mystring do
local account = string.sub(mystring,i,i)
local temp = string.byte(account)

    if 48 <= temp and temp <= 57 then                                
            
    elseif 65<= temp and temp <= 90 then
                
    elseif 97 <= temp and temp <= 122 then
                
    else
        cclog("输入包含非数字、字母的字符,不符合规则,请重新输入")
        return false
    end
end

end

感谢分享~~~:14:

楼主 你的方法很好 不过现在的版本遇到个问题
限制了字符之后 win32下是正常的 打包到手机上不会限制小键盘的输入
比如我限制只能输入数字 而我在手机小键盘里输入了:我hello
最终会把“我”屏蔽掉 但是hello写到控件上了 有没有办法在小键盘里直接限制

:13: :13: :13: :13: