我有这个功能,不允许任何特殊字符
请让我知道如何修改此功能,以便它也允许数字?
<input type="text" id="category" onkeypress="return nospecialCharacters(event,this)" class="m-wrap span12" placeholder="">
function nospecialCharacters(thi,dec)
{
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (((keycode>=65) && (keycode<=90))||((keycode>=97) && (keycode<=122)) || keycode==32)
{
return true;
}
else
{
return false;
}
}
这是我的jsfiddle
答案 0 :(得分:1)
使用ASCII表代码:
<input type="text" id="category" onkeypress="return nospecialCharacters(event,this)" class="m-wrap span12" placeholder="">
function nospecialCharacters(thi,dec)
{
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (((keycode>=48) && (keycode<=57))||((keycode>=65) && (keycode<=90)) ||((keycode>=97) && (keycode<=122)) || keycode==32)
{
return true;
}
else
{
return false;
}
}