仅允许某些字符 [英] Allow only certain characters

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

问题描述

我想阻止所有字符被输入,除了0-9,a-z,A-Z范围只有字母数字字符。所以当有人打字!例如,没有任何内容写入输入。我该怎么做?

I'd like to block all characters from being inputed except 0-9,a-z,A-Z range only alphanumeric characters. So when someone types ! for examplee nothing is written into input. How can I do that?

推荐答案

你需要编写一个侦听 onkeypress的函数表单字段的事件,然后检查表单是否包含任何不需要的字符,如果有,则更新删除了这些字符的字段。

You need to write a function that listens for the onkeypress event for the form field, then check to see if the form contains any unwanted characters, and if it does, you update the field with those characters removed.

这篇关于仅允许某些字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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