regex - ASP.NET Web API 2 Model Validation with Regular Expression -
in web api 2 controller have create method contains following logic:
if (((assignment.type).tolower() != "individual" && (assignment.type).tolower() != "staff")) { return request.createerrorresponse(httpstatuscode.badrequest, "the assignment type must either 'individual' or 'staff'"); }
i using model state validation. possible assign regular expression property eliminate need checking in controller? if so, reg ex return valid if exact string (case insensitive) of "individual" or "staff" passed user of api?
if want regex use
new regex(@"^(individual|staff)$", regexoptions.ignorecase)
but, recommend create enum corresponding values , make model property of enum.
Comments
Post a Comment