Skip to content

Pattern anchor #664

@Prinzhorn

Description

@Prinzhorn

When reading pattern from HTML it is used directly as a regular expression, which is not correct. The spec says

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).

That means native validation using pattern="\d{5}" only accepts exactly five numbers. But knockout validation will use this as a regular expression, which will accept anything that contains five numbers aynwhere. E.g. foo12345bar.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions