3
<!DOCTYPE html>
  <html>
    <head>  
      <title>Page Title</title>
    </head>
    <body>
      <form> 
        <input type="text"   placeholder="Mobile Number" required=""  style="width: 263px;" maxlength="10" minlength="10">
        <input type="submit">
      </form>
    </body>
  </html>

I'm trying to restrict the textbox validation by using maxlength and minlength CSS attributes, it is not working in IE (although working on other browsers).

TylerH
  • 20,799
  • 66
  • 75
  • 101

2 Answers2

4

It appears that minlength is not supported in most current browsers. There is a promising looking workaround here that you can try to use. Using maxlength and the workaround, your code should work.

TylerH
  • 20,799
  • 66
  • 75
  • 101
NathanOliver
  • 171,901
  • 28
  • 288
  • 402
1

Try this (javascript) solution:

<script>
function validateForm() {
  var errors = false;
  if(document.getElementById("mobile").val().length() != 10) {
    errors=true;
    alert("number must be 10 characters");
  }else{
    errors=false;
  }
  if(errors==false){
    document.getElementById("form").submit();
  }
}
</script>

<form method="post" id="form" onsubmit="return validateForm()">
  <input type="text" id="mobile" placeholder="Mobile Number" style="width: 263px;" maxlength="10" minlength="10">
  <input type="submit">
</form>
Kim Janssens
  • 339
  • 4
  • 13