textarea/input maxlength Parity

Measures an input or textarea API value in UTF-16 code units against maxlength. Supply the already-normalized API value; this does not model user-edit constraint-validation conditions or grapheme counts.

Description

HTML maxlength counts UTF-16 code units in a control’s API value.

HTML maxlength counts UTF-16 code units in a control’s API value. A displayed character can occupy multiple units, so visible character counts can differ.1

Measures an input or textarea API value in UTF-16 code units against maxlength. Supply the already-normalized API value; this does not model user-edit constraint-validation conditions or grapheme counts.

When to use textarea/input maxlength Parity

Use this for the following task: Measures an input or textarea API value in UTF-16 code units against maxlength. Supply the already-normalized API value; this does not model user-edit constraint-validation conditions or grapheme counts.

Prepare the parsed attribute values, element states or ordered local lists requested below. Keep attribute presence separate from value.

How to use textarea/input maxlength Parity and understand its results

  1. Prepare the parsed attribute values, element states or ordered local lists requested below. Keep attribute presence separate from value.
  2. Enter value, maxlength using the field table, then run the tool.
  3. Read codeUnits, withinLimit, excess. Interpret flags, units, ordering and placeholder values using the rules below.
  4. Review any reported issue or failed check, correct the supplied values when appropriate, and verify the result in its intended context.
Input fieldMeaningValue type and boundsRequirement
valueValuestring; maximum text length 100000Required
maxlengthMaxlengthinteger; minimum 0Required

Use the normalized input or textarea API value. Compare its JavaScript length with maxlength inclusively; return withinLimit and the nonnegative excess.2

codeUnits = value.length; excess = max(0, codeUnits − maxlength)

This summarizes the declared operation. Units, indexing, inclusivity and exceptional cases are explained in the surrounding text.

Output fieldMeaningValue type
codeUnitsCode Unitsinteger
withinLimitWithin Limitboolean
excessExcessinteger
json
{
  "input": {
    "value": "A😀B",
    "maxlength": 3
  },
  "output": {
    "codeUnits": 4,
    "withinLimit": false,
    "excess": 1
  }
}

Limitations and assumptions

This does not count grapheme clusters or reproduce the user-edit conditions for browser constraint validation.

This evaluates supplied local information; it does not fetch a page or run a browser. Malformed requests produce input errors. A successfully evaluated request can still contain false flags, empty result lists or a result outside the supplied threshold; those outcomes have the meanings stated above.

Alternative or Complementary methods

Choose required/readonly/disabled Diff Table for this operation: Resolves required, readonly and disabled flags for an ordinary input type. Effective disabled includes inherited fieldset state supplied by the caller. Submission eligibility concerns disabling only; name, checkedness and submitter selection are separate. For a complementary task, use min/max/step Number Input Semantics for this operation: Checks parsed number-input min/max and step constraints using exact decimal arithmetic on the canonical decimal spelling of supplied finite numbers. Supply normalized positive step (default 1) and attribute presence flags; this is an ideal decimal model, independent of browser binary floating point tolerances.

Further background: HTML / accessibility reference: textarea/input maxlength Parity.

References

  1. HTML / accessibility reference: textarea/input maxlength Parity — WHATWG

  2. textarea/input maxlength Parity — tool.io

Similar or alternative tools

  • required/readonly/disabled Diff Table

    Resolves required, readonly and disabled flags for an ordinary input type. Effective disabled includes inherited fieldset state supplied by the caller. Submission eligibility concerns disabling only; name, checkedness and submitter selection are separate.

  • min/max/step Number Input Semantics

    Checks parsed number-input min/max and step constraints using exact decimal arithmetic on the canonical decimal spelling of supplied finite numbers. Supply normalized positive step (default 1) and attribute presence flags; this is an ideal decimal model, independent of browser binary floating point tolerances.

Don't forget to set a bookmark for tool.io!
Privacy | Imprint | Cookies