限制表单输入文本字段中允许的字符数 [英] Limit number of characters allowed in form input text field
问题描述
如何限制或限制用户在文本框中最多输入5个字符?
How do I limit or restrict the user to only enter a maximum of five characters in the textbox?
以下是输入字段作为我的表单的一部分:
/ p>
Below is the input field as part of my form:
<input type="text" id="sessionNo" name="sessionNum" />
是否使用类似maxSize或类似的东西?
Is it using something like maxSize or something like that?
推荐答案
maxlength:
将被接受为输入的字符的最大数量。这可以通过SIZE指定的更大,在这种情况下,
字段将适当滚动。
The maximum number of characters that will be accepted as input. This can be greater that specified by SIZE , in which case the field will scroll appropriately. The default is unlimited.
<input type="text" maxlength="2" id="sessionNo" name="sessionNum" onkeypress="return isNumberKey(event)" />
但是,这可能会或可能不会受到您的处理程序的影响。您可能需要使用或添加其他处理函数来测试其长度。
However, this may or may not be affected by your handler. You may need to use or add another handler function to test for length, as well.
这篇关于限制表单输入文本字段中允许的字符数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!