鉴别一串字符串中只包含数字

--string   需要鉴定的字符串
--返回值    true是全数字
function UIBase:judgeIsAllNumber(string, displayCenter)
local isAllNum = false


--先屏蔽加号和空格

local s1, e1 = string.find(string, "+")

local s2, e2 = string.find(string, " ")

if s1 ~= nil or e1 ~= nil or  s2 ~= nil or e2 ~= nil then
isAllNum = false
else
--判断是否有其他符号或者文字
local n = tonumber(string)
if n then
-- print("this num is  ======= " .. n)
if n<0 then
--是负数,肯定有负号
isAllNum = false
else
local pn = getIntPart(n) --此处为取整数部分参见http://blog.csdn.net/daydayup_chf/article/details/46351947
-- print("number int part ====== " .. pn)


if pn == n then
-- print("***********************")
isAllNum = true
else
--不相等说明有小数点
isAllNum = false
end
end
else
isAllNum = false
-- print("this string is not a number !!!!!")
end
end


--提示
if isAllNum == false then
-- print("not is all number !!!!!!!!!!!!")
self:inputSysTips(InputIsNumber, displayCenter)
end


return isAllNum
end
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值