我有一种方法,在webapi中,我正在使用swagger调用Web api。在api request中,“ request type”参数应仅允许使用字母,数字和点(。)。 我已经尝试过下面的代码,但是不能正常工作
[HttpGet]
[SwaggerResponse(HttpStatusCode.OK, Type = typeof(string))]
[Route(@"testMethod/{requestType:regex(^[A-Za-z0-9. ]+$)}")]
public IHttpActionResult testMethod(int mid,string requestType = "", )
{
//logic
}
答案 0 :(得分:3)
在正则表达式中,点通常是任何字符的占位符。因此,您必须逃避它。在.NET中,这是用反斜杠完成的:A-Za-z0-9\.
答案 1 :(得分:0)
这可能有效:
[a-zA-Z]|\d|\s|\.*