Regex Data Annotation no dotnet core

Asked

Viewed 30 times

0

to consuming an external api and one of the properties has hyphen: position-number.

How can I put a note so that I can receive this amount? I am trying this way:

[Regularexpression(@" [a-za-Z''-' s]$", Errormessage = "Characters are not allowed." )] public Object position-number;

  • Try that regular expression here: [a-za-Z d-]+$

  • Your problem is to parse this parameter or validate in your model?

1 answer

0

If the data structure you are receiving or sending has a hyphen in the key (not the value), then you need to map pro(de)serialize.

If it is JSON:

[JsonProperty("position-number")]
public string PositionNumber { get; set; }

If it is XML:

[DataMember(Name = "position-number")]
public string PositionNumber { get; set; }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.