仅允许使用jQuery的字母文本框? [英] Allow text box only for letters using jQuery?

查看:105
本文介绍了仅允许使用jQuery的字母文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让一个文本框只允许使用jQuery的字母(a-z)。
任何例子?

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

推荐答案

<input name="lorem" onkeyup="this.value=this.value.replace(/[^a-z]/g,'');">

并且可以与 onblur 相同喜欢粘贴而不是打字的邪恶用户;)

And can be the same to onblur for evil user who like to paste instead of typing ;)

[+]漂亮的jQuery代码:

[+] Pretty jQuery code:

<input name="lorem" class="alphaonly">
<script type="text/javascript">
$('.alphaonly').bind('keyup blur',function(){ 
    var node = $(this);
    node.val(node.val().replace(/[^a-z]/g,'') ); }
);
</script>

这篇关于仅允许使用jQuery的字母文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆