anthonypliu
anthonypliu

Reputation: 12437

how to add white space into conditional regex

I have the following data annotation for one of my properties:

[RegularExpression(@"A|B|C|A and B", ErrorMessage = "You must select one.")]

When I submit the value "A and B" it does not accept this, but if i post "A", "B", or "C" it passes. How would i make it so the full string "A and B" will accept.

Upvotes: 0

Views: 91

Answers (1)

akton
akton

Reputation: 14376

Put the "A and B" in parentheses:

[RegularExpression(@"A|B|C|(A and B)", ErrorMessage = "You must select one.")]

Upvotes: 1

Related Questions