Skip to content
This repository was archived by the owner on Nov 27, 2018. It is now read-only.
This repository was archived by the owner on Nov 27, 2018. It is now read-only.

Using square brackets in regex constraints #373

@vaindil

Description

@vaindil

I have a controller that accepts either an ID or a string at a given endpoint. I have the ID function set correctly using api/departments/{id:long}, but I cannot figure out how to route to the string endpoint. The alpha constraint is not enough as the string can contain numbers.

I'm trying to use this route to accept any valid string but require that the first character be a letter.

[Route("api/departments/{deptName:regex(^[a-zA-Z]{1}[a-zA-Z0-9_]*$)}")]

This does not work, however:

For action: 'Namespace.DepartmentsNameController.Get (Namespace)'
Error: While processing template 'api/departments/{deptName:regex(^[a-zA-Z]{1}[a-zA-Z0-9_]*$)}', a replacement value for the token 'a-zA-Z' could not be found. Available tokens: 'action, controller'.

What is the correct way to approach this?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions