我想使用jquery阻止输入字段中的所有特殊字符,这样做有什么建议吗?
答案 0 :(得分:1)
答案 1 :(得分:1)
允许alpha only char的简单函数:
function AlphaNumericOnly(e,isAlphaonly)
{
// copyright 1999 Idocs, Inc. http://www.idocs.com
var key = [e.keyCode||e.which];
var keychar = String.fromCharCode([e.keyCode||e.which]);
keychar = keychar.toLowerCase();
if(isAlphaonly=='true')
checkString="abcdefghijklmnopqrstuvwxyz";
else
checkString="abcdefghijklmnopqrstuvwxyz0123456789";
if ((key==null) || (key==0) || (key==8) ||
(key==9) || (key==13) || (key==27) )
return true;
else if (((checkString).indexOf(keychar) > -1))
return true;
else
return false;
}