Javascript DOM HTML Input Email maxLength Property set

Introduction

Set the maximum number of characters allowed in an email field:

document.getElementById("myEmail").maxLength = "8";

Click the button to set the maximum number of characters allowed in the email field.

View in separate window

<!DOCTYPE html>
<html>
<body>

E-mail: <input type="email" id="myEmail">
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from   w ww .  ja va  2 s.c  o m*/
  document.getElementById("myEmail").maxLength = "8";
  document.getElementById("demo").innerHTML = "Maximum number of characters allowed in the email field is now 8.";
}
</script>

</body>
</html>



PreviousNext

Related