Allow text box only for letters using jQuery?

后端 未结 11 1591
情书的邮戳
情书的邮戳 2020-11-29 04:42

I want to make a text box allow only letters (a-z) using jQuery. Any examples?

11条回答
  •  Happy的楠姐
    2020-11-29 05:08

      $("#test").keypress(function(event){
            var inputValue = event.charCode;
            //alert(inputValue);
            if(!((inputValue > 64 && inputValue < 91) || (inputValue > 96 && inputValue < 123)||(inputValue==32) || (inputValue==0))){
                event.preventDefault();
            }
        });
      $("#test1").keypress(function(event){
            var inputValue = event.charCode;
            //alert(inputValue);
            if(!((inputValue > 47 && inputValue < 58) ||(inputValue==32) || (inputValue==0))){
                event.preventDefault();
            }
        });
    
      $("#test3").keypress(function(event){
            var inputValue = event.charCode;
            //alert(inputValue);
            if(!((inputValue > 64 && inputValue < 91) || (inputValue > 96 && inputValue < 123)||(inputValue==32)||(inputValue > 47 && inputValue < 58) ||(inputValue==32) || (inputValue==0))){
                event.preventDefault();
            }
        });
    
    For letters:   

    For Numbers:

    For Alphanumeric:

提交回复
热议问题