I have tried:
[RegularExpression(@"\n", ErrorMessage = "Error")] // Needs to not allow newline characters
public string ImageMimeType { get; set; }
but it always fails when I attempt to upload a legitimate .bmp file.
I am not sure how to format this line appropriately to prevent newline characters.
Also – are there any other considerations I should take when validating a MIME type?
Solved
[RegularExpression(@"[^\n]+", ErrorMessage = "Error")]
You are just specifying
\nas the regex. Your legitimate files will not be matching\nand hence they are treated asNO_MATCH. You want it the other way. ie the filename mustn’t contain\n. TryThis says, match a string of 1-any number of characters ( you can specify string range using {m,n} syntax if you wish to) not containing a newline character.