Skip to content

Fix regex validator crash on invalid patterns in jquery.validate.unobtrusive.js #67028

@ishaq2321

Description

@ishaq2321

Issue

The regex custom validator in jquery.validate.unobtrusive.js (shipped with ASP.NET Core Identity UI) throws a SyntaxError when new RegExp(params) encounters an invalid regex pattern from data-val-regex-pattern. This crashes all client-side form validation on the page.

Steps to Reproduce

A [RegularExpression] attribute with an invalid pattern (e.g., unbalanced brackets) generates a data-val-regex-pattern attribute. When jQuery Validate evaluates new RegExp(params), it throws.

Proposed Fix

Wrap the new RegExp() call in a try-catch so invalid patterns skip validation gracefully instead of crashing. Server-side validation at form submission remains the authoritative fallback.

Found via static analysis of the ASP.NET Core codebase.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templates

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions