Mostly it has to do with Regular expression.
1. You need to create a regular expression to validate the text.
/^[a-zA-Z0-9]{1,11}$/
2. Bind the textbox with keypress event.
3. Use the following code.
$('#txtAlpha').keypress(function(e)
{
var code = e.keyCode ? e.keyCode:e.which; // Get the key code.
var pressedKey = String.fromCharCode(code); // Find the key pressed.
if(pressedKey.match(/[a-zA-Z0-9]/g)) // Check if it's a alpanumeric char or not.
{
e.preventDefault(); // If it is not then prevent the event from happening.
}
});
Ready made example can be found here:
http://jsfiddle.net/syS4G/ Hariinakoti, if this helps please login to Mark As Answer. | Alert Moderator