输入框禁止输入特殊字符

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/shangazhe/article/details/54692356

<input type="text" class="input-text" value="" placeholder="" id="lHousehold" name="lHousehold" οnkeyup="ValidateValue(this)" maxlength="200">

//禁止输入特殊字符

function ValidateValue(textbox) {
var IllegalString = "\`~@#;,.!#$%^&*()+{}|\\:\"<>?-=/,\'";
var textboxvalue = textbox.value;
var index = textboxvalue.length - 1;


var s = textbox.value.charAt(index);


if(IllegalString.indexOf(s) >= 0) {
s = textboxvalue.substring(0, index);
textbox.value = s;
}
}
展开阅读全文

没有更多推荐了,返回首页