zoukankan      html  css  js  c++  java
  • Javascript 判断整型、浮点型、去空格

     1 <script language="javascript">
     2     //判断是否是整数
     3     function isNum(str) 
     4     {
     5         var i;
     6         for(i=0; i<str.length; i++
     7         {
     8             if (str.charAt(i) == "."
     9             {
    10                 return false;
    11             }
    12         }
    13         return !isNaN(str);
    14     }
    15                 
    16     //整型判断
    17     function checkInt(e)
    18     {
    19         e.value = e.value.replace(/\s/g,""); 
    20         
    21         if(e.value.length > 0)
    22         {
    23             //有效数值判断
    24             if(isNaN(e.value))
    25             {   
    26                 alert('无效数值,请重新输入!')
    27                 e.value='';   
    28                 setTimeout('document.all['+e.sourceIndex+'].focus()',10)   
    29             }
    30             
    31             //正数判断
    32             if(e.value < 0)
    33             {
    34                 alert("不能小于0,请重新输入!"); 
    35                 e.value='';  
    36                 setTimeout('document.all['+e.sourceIndex+'].focus()',10)
    37             }
    38             
    39             //整数判断
    40             if(isNum(e.value) == false)
    41             {
    42                 alert("必须是整数,请重新输入!"); 
    43                 e.value='';  
    44                 setTimeout('document.all['+e.sourceIndex+'].focus()',10)
    45             }
    46         }
    47     }
    48     
    49     //浮点型判断
    50     function checkFloat(e)
    51     {
    52         e.value = e.value.replace(/\s/g,""); 
    53         
    54         if(e.value.length > 0)
    55         {
    56             //有效数值判断
    57             if(isNaN(e.value))
    58             {   
    59                 alert('无效数值,请重新输入!')
    60                 e.value='';   
    61                 setTimeout('document.all['+e.sourceIndex+'].focus()',10)   
    62             }
    63             
    64             //正数判断
    65             if(e.value < 0)
    66             {
    67                 alert("不能小于0,请重新输入!"); 
    68                 e.value='';  
    69                 setTimeout('document.all['+e.sourceIndex+'].focus()',10)
    70             }
    71         }
    72     }
    73 </script>
    1 <asp:textbox id="tb" runat="server" onblur="checkFloat(this)"></asp:textbox>
  • 相关阅读:
    [vue][element-ui]mousedown在Dialog上 mouseup在遮罩上时自动关闭弹窗的问题总结
    [ESlint]报错:使用async await时,报(local function)(): Promise<void> Parsing error: Unexpected token function
    [ESlint]报错:Vue eslint Parsing error: Unexpected token
    [CSS]position梳理
    [Node]报错:gyp verb check python checking for Python executable "python2" in the PATH
    [Node]报错:node-sassvendorwin32-x64-79inding.node Node Sass could not find a binding for your current environment: Windows 64-bit with Node.js 13.x
    Failed to start OpenLDAP Server Daemon
    与或
    struts2启动报错
    UIButton
  • 原文地址:https://www.cnblogs.com/tohen/p/1684634.html
Copyright © 2011-2022 走看看