文本框输入限制

1.不能输入空格
<input type="text" onkeyup="this.value=this.value.replace(/^ +| +$/g,'')">

2.只允许输入数字
<input type="text" name="number" id="number" onkeyup="this.value=this.value.replace(/[^d]/g,'');" />

3.不能输入空格及英文状态下的逗号
<input type="text" onkeyup="this.value=this.value.replace(/[, ]/g,'')">

4.不能输入空格函数方法

<input name="mjinput" onkeydown="return NoSapceInput(event);" type="text" />

function noSapceInput(evt) {
    evt = window.event || evt;
    var key = 'which' in e ? e.which : e.keyCode;
    if (key == 32 || key == 188 || key == 222) {
        // alert("禁止输入空格");
        return false;
    }
    return true;
}
原文地址:https://www.cnblogs.com/mengff/p/7520899.html