1

I have the folowing regex on my MVC view model (p.s. all other regex`es work fine)

[Required, MaxLength(256)]
[RegularExpression(@"/(\[Brand name\])/i", ErrorMessage = "Reply message <strong> Must</strong> contain <strong>[Brand name]</strong>")]
public string ReplyMessage { get; set; }

enter image description here

Mike Perrenoud
  • 66,820
  • 29
  • 157
  • 232
Marty
  • 3,485
  • 8
  • 38
  • 69
  • 1
    .NET regex pattern strings do not require (and must not have) regex delimiters. So instead of: `@"/(\[Brand name\])/i"` use: `@"(?i)(\[Brand name\])"`. – ridgerunner Aug 28 '13 at 14:22
  • @ridgerunner Actually, that should be an answer. – Leri Aug 28 '13 at 14:23

1 Answers1

1

Unless I'm misunderstanding the need, the regex should be:

.*(\[Brand name\]).*

Or in other words, any character before and after, but must contain "[Brand name]".

Mike Perrenoud
  • 66,820
  • 29
  • 157
  • 232