Skip to content

Proposal: New HTML attributes mustcontain, requiredchars, and preset for simplified form validation #11538

@sanketbhuite

Description

@sanketbhuite

What problem are you trying to solve?

Current HTML form validation relies heavily on the pattern attribute, which requires regular expressions.
For common needs (e.g., “must include uppercase, lowercase, and a number”), regex patterns become hard to read, maintain, and understand—especially for beginners.
Many developers end up using JavaScript for basic validation, which defeats the purpose of having built-in browser validation.

What solutions exist today?

pattern attribute (powerful but regex is complex)

<input type="password" pattern="^(?=.*[A-Z])(?=.*\d).+$">

JavaScript validation (flexible but adds extra code and isn’t standardized)
if (!/[A-Z]/.test(value) || !/\d/.test(value)) { /* custom check */ }

Third-party libraries (more dependencies, not native to HTML)
These approaches work but are either hard to write or not standardized.

How would you solve it?

Introduce new semantic attributes that simplify common character requirements without regex:

<!--Require certain character types -->
<input type="text" requiredchars="uppercase,digit">

<!-- Require specific counts -->
<input type="password" mustcontain="uppercase:1,digit:2,symbol:1">

<!-- Use a preset for strong password -->
<input type="password" preset="strongpassword">

Key points:

requiredchars: At least one of each listed type (uppercase, lowercase, digit, symbol).

mustcontain: Specific counts for each type.

preset: Built-in predefined rules (e.g., strongpassword = uppercase+lowercase+digit+symbol+min length 8).

Browsers can internally translate these into equivalent regex or validation logic.
Backward compatibility is preserved because unknown attributes are ignored by browsers that don’t support them.

Anything else?

Polyfill example: This can be simulated today using JavaScript, proving feasibility.

Developer benefit: No regex knowledge required, validation is more semantic.

Browser benefit: Minimal change—just parse and validate attributes similar to pattern.

User benefit: Consistent behavior across browsers without extra scripts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    addition/proposalNew features or enhancementsneeds implementer interestMoving the issue forward requires implementers to express interest

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions