开发者

prevent special characters in input fields using jquery

I want to block all special characters in the input fields us开发者_运维技巧ing jquery, any suggestion in doing this?


You can also check the more specific alphanumeric plugin

Example:

$('.sample1').alphanumeric();

Allows alphabet and numeric characters


Simple function to allow 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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜