Click here to Skip to main content
15,905,563 members
Please Sign up or sign in to vote.
2.60/5 (3 votes)
See more:
can anybody please provide me jquery code on keypress

on following keys

a-z,A-Z,/ - _
Posted
Comments
Sampath Lokuge 1-Apr-14 3:36am    
Can you give more info about your situation ?

Try this:
XML
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("input").keypress(function(event){

       //KeyCode 65-90 is A-Z
       //KeyCode 97-122 is a-z

    if((event.which >= 65 && event.which <= 90) ||
         (event.which >= 97 && event.which <= 122) ||
         (event.which == 45) ||  // -
         (event.which == 47) ||  // /
         (event.which == 95))    // _
    {
        return true;
    }else{
        return false;
    }
  });
});
</script>
</script>
</head>
<body>
<input type='text' />
</body>
</html>
 
Share this answer
 
v2
Comments
Sampath Lokuge 1-Apr-14 4:23am    
+5 :)
$( "#target" ).keypress(function( event ) {
console.log(event.keyCode);
}


Keycode for:
+ a-z: 97-122
+ A-Z: 65-90
/ : 47
- : 45
_ : 95
 
Share this answer
 
visit here............

Jquery onKeyPress Event[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900