如何在文本框中设置最大长度6和最小长度6? [英] How can I set the maximum length of 6 and minimum length of 6 in a textbox?
本文介绍了如何在文本框中设置最大长度6和最小长度6?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑:
<input id="groupidtext" type="text" style="width: 100px;" maxlength="6" /></td>
是否可以将最小长度设置为6?
Is there a way to set the minimum length to 6?
推荐答案
您可以使用JavaScript执行以下操作:
You could do it with JavaScript with something like this:
<input onblur="checkLength(this)" id="groupidtext" type="text" style="width: 100px;" maxlength="6" />
<!-- Or use event onkeyup instead if you want to check every character strike -->
function checkLength(el) {
if (el.value.length != 6) {
alert("length must be exactly 6 characters")
}
}
请注意,这可以在不支持HTML 5的旧版浏览器中使用,但它依赖于已打开JavaScript的用户.
Note this would work in older browsers which don't support HTML 5, but it relies on the user having JavaScript switched on.
这篇关于如何在文本框中设置最大长度6和最小长度6?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文