开发者

prevent special characters in input fields using jquery

开发者 https://www.devze.com 2023-01-01 01:07 出处:网络
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

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

精彩评论

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