tags:

views:

106

answers:

2

Hi, I want to block all special characters in the input fields using jquery, any suggestion in doing this?

A: 

You can also check the more specific alphanumeric plugin

Example:

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

Allows alphabet and numeric characters

DrDro
Thanks DrDro,this is very much helpful.
+1  A: 

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;
}
Pranay Rana
Hi Pranay, thank you very much for this.