Allow text box only for letters using jQuery?

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

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

11条回答
  •  眼角桃花
    2020-11-29 05:08

    // allow only  Alphabets A-Z a-z _ and space
    $('.alphaonly').bind('keyup blur',function(){ 
        var node = $(this);
        node.val(node.val().replace(/[^A-Za-z_\s]/,'') ); }   // (/[^a-z]/g,''
    );
    // allow only  Number 0 to 9
    $('.numberonly').bind('keyup blur',function(){ 
        var node = $(this);
        node.val(node.val().replace(/[^0-9]/,'') ); }   // (/[^a-z]/g,''
    );
    

提交回复
热议问题