如何只接受文本框ASP中的字母和空格 [英] How to accept only letters and space in textbox ASP

查看:84
本文介绍了如何只接受文本框ASP中的字母和空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我们最近正在使用我的验证。我验证我的文本框只允许使用此代码的数字

hello guys im working with my validations recently. i validate my text box to allow only numbers using this code

onkeydown = "return (!(event.keyCode>=65) && event.keyCode!=32);"

我怎样才能将其转换为仅允许空格和字母?



我尝试了什么:



onkeydown =return(!(event.keyCode> = 65)&& event.keyCode!= 32);

how can i convert this to allow only spaces and letters only ?

What I have tried:

onkeydown = "return (!(event.keyCode>=65) && event.keyCode!=32);"

推荐答案

没有尝试过,但下面的内容应该可以完成你的工作 -

Haven't tried it but something like following should do your job-
onkeydown = "return((event.keyCode >= 65 && event.keyCode <= 120) || (event.keyCode==32));"





希望,它会有所帮助。

如果它不起作用,请告诉我。



注意:建议使用正则表达式为了更好更容易的解决方案。



Hope, it helps.
If it doesn't work, please let me know.

Note: Would suggest to use regex for better and easier solution.


如果是o nkeydown事件,那么它应该是:

If it is for onkeydown event, then it should be:
return (event.keyCode>=65 && event.keyCode<=90 || event.keyCode==32);



捕获实际的键盘键。

检查出来:键盘事件| JavaScript教程 [ ^ ]

+++++ [round 2] +++++


to capture the actual keyboard key.
Check this out: Keyboard events | JavaScript Tutorial[^]
+++++[round 2]+++++

引用:

它运行良好但是我无法擦除?无法使用退格:O

it functions well but i cannot erase?cannot use backspace :O



然后添加一个条件来检查退格键,


Then add one more condition to check for backspace key,

return (event.keyCode>=65 && event.keyCode<=90 || event.keyCode==32 || event.keyCode==8);



请参阅此处了解JavaScript中的其他密钥代码 KeyboardEvent Value(keyCodes,metaKey等)| CSS-Tricks [ ^ ]

+++++ [第3轮] +++++


Refer to this for other keycodes in JavaScript KeyboardEvent Value (keyCodes, metaKey, etc) | CSS-Tricks[^]
+++++[round 3]+++++

引用:

嘿man我现在测试的另一个问题是验证并且只允许数字和冒号和退格我试试这个代码onkeydown =return(!(event.keyCode> = 65&& event.keyCode!= 32 || event。 keyCode == 186 || event.keyCode == 8;但它对我来说效果不好?

hey man another question i tested now to validate and allow only numbers and colon and backspace i try this codes onkeydown = "return (!(event.keyCode>=65 && event.keyCode!=32 || event.keyCode==186 || event.keyCode==8;" but it didnt work well for me ?



我已经给你足够的代码和参考,由你来理顺你的逻辑。如果你想接受数字,数字的键码范围是多少?如果你不想接受空格,为什么还要包括它,然后检查它不是?观察语法。


I have given you enough code and reference, It is up to you to straighten up your logic. If you want to accept numbers, what is the range of keycodes for numbers? If you do not want to accept space, why bother including it then checking that it is not? Watch the syntax too.


这篇关于如何只接受文本框ASP中的字母和空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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