The maxLength
property sets or gets the maxlength attribute of an email field.
The maxLength
attribute from input email element
specifies the maximum number of characters allowed in the email field. The default value is 524288.
maxLength |
Yes | 10.0 | Yes | Yes | Yes |
Return the maxLength property.
var v = emailObject.maxLength
Set the maxLength property.
emailObject.maxLength=number
Value | Description |
---|---|
number | Set the maximum number of characters allowed in the email field. Default value is 524288 |
A Number type value representing the maximum number of characters allowed in the email field.
The following code shows how to set the maximum number of characters allowed in an email field.
<!DOCTYPE html>
<html>
<body>
<!--from w w w.ja v a 2 s .c o m-->
E-mail: <input type="email" id="myEmail">
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
document.getElementById("myEmail").maxLength = "8";
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to get the maximum number of characters allowed in a specific email field.
<!DOCTYPE html>
<html>
<body>
E-mail: <input type="email" id="myEmail" maxlength="30">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!-- w w w . j a v a2 s .c o m-->
var x = document.getElementById("myEmail").maxLength;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: