如何在文本框中设置最大长度为6和最小长度为6? [英] How to set max length of 6 and minimum length of 6 in a textbox?

查看:374
本文介绍了如何在文本框中设置最大长度为6和最小长度为6?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < input id =groupidtexttype =textstyle =width:100px; maxlength =6/>< / td> 

有没有办法让最小长度为6?
<你可以用javascipt来做到这一点:

 < input onblur =checkLength(this)id =groupidtexttype =textstyle =width:100px; maxlength =6/> 
<! - 或者使用事件onkeyup,而不是想要检查每个字符罢工 - >


函数checkLength(el){
if(el.value.length!= 6){
alert(length must be 6 characters)


b



请注意,这种方法适用于不支持旧版本的浏览器HTML 5,但依赖于开启了javascript的用户。

 <input id="groupidtext" type="text" style="width: 100px;" maxlength="6" /></td>

Is there any way to get the minimum length to 6?

解决方案

you could do it with javascipt 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")
  }
}

Note this would work in older browsers which don't support HTML 5, but relies on the user having javascript switched on.

这篇关于如何在文本框中设置最大长度为6和最小长度为6?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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