想让一个输入框只能输入数字和-,-可以不在第一位。
复制粘帖的时候,把非数字和-替换成空。
谢谢大家

解决方案 »

  1.   


    <input type="text" /><span id='tip'></span>
    <script type="text/javascript">
    function check(o) {
         var v = $(o).val();
    if(v == '') {
    return;
    }
    if(!(/^[\d-]+$/g).test(v)) {
    v = v.replace(/[^\d-]/g, '');
    $(o).val(v);
    }
    }
    $("input[type='text']").bind('keyup', function() {
    check(this);
    }).bind('click', function() {
    check(this);
    }).bind('paste', function() {
    check(this);
    })
    </script>
      

  2.   


    <script type="text/javascript">
    function FormatValue(Obj){
      Obj.value = Obj.value.replace(/[^\-\d]/g, "");
    }
    function CopyValue(Obj){
      if(window.clipboardData){
        window.clipboardData.clearData();
        window.clipboardData.setData("Text", Obj.value.replace(/-/g, ""));
      }
      return false;
    }
    </script>
    <input type="text" onkeyup="FormatValue(this);" onblur="FormatValue(this);" oncopy="return CopyValue(this);" oncut="return CopyValue(this);" />