While it’s possible to use
form data entry, this approach
may not be trustworthy if the client has been affected by a nefarious
script). Server–side validation is a much safer option, and could be used,
among other things, to check that the amount of data submitted isn’t too
maxlength attribute provides a means for
reducing—but still not completely eliminating—the likelihood that
too much data will be sent to the server for processing. It is primarily a
usability enhancement, indicating to users when they’ve reached the
maximum character length for an input, thus avoiding the chance of writing
an essay only to be told afterwards that there is a max character count of
maxlength attribute restricts entries in this
password field to a maximum of four characters:
<form> <label for="pin">Your 4-digit PIN:</label> <input type="password" name="pin" id="pin" maxlength="4" size="6"/> ⋮ </form>
The value for this attribute is a number which represents the total characters that can be submitted.
It causes no compatibility issues, and has excellent support across all tested browsers.