Get the maximum number of characters allowed in a specific email field:
var x = document.getElementById("myEmail").maxLength;
Click the button to display the value of the maxlength attribute of the 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() {//from w ww. j a v a 2 s . c om var x = document.getElementById("myEmail").maxLength; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The maxLength
property sets or gets the value of the maxlength attribute of an email field.
The maxLength attribute sets the maximum number of characters allowed in the email field.
To set or return the width of an email field, in number of characters, use the size
property.
The maxLength
property accepts and returns a number type value.