且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在文本框中设置最大长度为6和最小长度为6?

更新时间:2023-10-12 14:23:34

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.