Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

patternDirective does not adhere to as how pattern is specified in HTML5 #9881

Closed
@gweax

Description

@gweax

On an input like that

    <input type="password" pattern="\d{4}" ng-model="pin">

Angular accepts an input of four or more digits, while browsers only accept an input of exactly four digits. See http://plnkr.co/edit/9LeAPND933Byv4uQ3dT9?p=preview
The reason behind this, is that the standard implies the pattern to have to match the whole string [1]:

The compiled pattern regular expression, when matched against a string, must have its start anchored to the start of the string and its end anchored to the end of the string.

This implies that the regular expression language used for this attribute is the same as that used in JavaScript, except that the pattern attribute is matched against the entire value, not just any subset (somewhat as if it implied a ^(?: at the start of the pattern and a )$ at the end).

In my opinion, Angular should follow the spec. Yet I am aware that a fix would be a breaking change.

[1] https://html.spec.whatwg.org/multipage/forms.html#attr-input-pattern

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions