1
我在我的web api項目中添加了一個過濾器來驗證從客戶端傳遞的所有模型。爲了驗證模型,我使用數據註釋。這一切似乎工作正常,除非我使用RegularExpression註釋。使用RegularExpression註釋驗證模型
這是過濾器我有我的API:
public override void OnActionExecuting(HttpActionContext actionContext)
{
if (actionContext.ModelState.IsValid == false)
{
actionContext.Response = actionContext.Request.CreateErrorResponse(
HttpStatusCode.BadRequest, actionContext.ModelState);
}
}
這是不是正確驗證模型屬性:
[Required]
[MinLength(8)]
[StringLength(255)]
[RegularExpression(@"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)", ErrorMessage = "Password must contain at least one capital letter and one number")]
public string Password { get; set; }
不管我把這個字符串在什麼樣的價值觀,我不斷收到錯誤。任何幫助,將不勝感激。
就是這樣!謝謝! – jorgenv 2014-10-29 01:00:25
@jorgenv,歡迎。 – 2014-10-29 02:35:36