zoukankan      html  css  js  c++  java
  • asp.net客户端脚本验证小技巧

     通用的客端脚本验证

    Code

    页面里的规则:

    姓名:<input name="txttime" id="txttime" type="text" islaw="true" hint="姓名" />

    省份:<asp:DropDownList ID="ddloffice" runat="server" hint="省份" isdrop="true" >
    </asp:DropDownList>

    (注:由于我只需要是否为空和非法字符,所以只添加了hint,islaw,isdrop属性,若你有更多的需要,可以添加更多的属性,属性名只要能通过dom解析就OK了)

     

     

    只能输入数字

    onkeyup="value=value.replace(/[^\d]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"
    示例:
    <input type="text" id="a" name="a" onkeyup="value=value.replace(/[^\d]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" />

     

    只能输入小数

     style="ime-mode:Disabled;" onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')"
     示例:
    <input type="text" id="a" name="a" style="ime-mode:Disabled;" onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')"/>

     

    控件textarea的输入文本长度

    <textarea id="txtinfo" name="txtinfo" rows="3" cols="70" class="txt" runat="server" onpropertychange="if(this.value.length>200){this.value=this.value.substr(0,200)}"></textarea>


     

  • 相关阅读:
    Spring boot unable to determine jdbc url from datasouce
    Unable to create initial connections of pool. spring boot mysql
    spring boot MySQL Public Key Retrieval is not allowed
    spring boot no identifier specified for entity
    Establishing SSL connection without server's identity verification is not recommended
    eclipse unable to start within 45 seconds
    Oracle 数据库,远程访问 ora-12541:TNS:无监听程序
    macOS 下安装tomcat
    在macOS 上添加 JAVA_HOME 环境变量
    Maven2: Missing artifact but jars are in place
  • 原文地址:https://www.cnblogs.com/linyechengwei/p/1358290.html
Copyright © 2011-2022 走看看