I have an asp.net MVC application. There is an entity called File that it has a property called Name.
using System.ComponentModel.DataAnnotations;
public class File {
...
[RegularExpression(@"([^.]+[.](jpg|jpeg|gif|png|wpf|doc|docx|xls|xlsx ..., ErrorMessage = "Invali File Name"]
public string Name{ get; set; }
...
}
There is a RegularExpressionValidator that checks file extensions.
Is there a quick way I can tell it to ignore the case of the extension without having to explicitly add the upper case variants to my validation expression?
I need this RegularExpressionValidator for both Server-side and client-side.
“(?i)” can be used for Server-side, but this doesn’t work client-side
One way I can think of is writing a custom validation attribute:
and then decorate your model with it:
Finally write an adapter on the client:
Of course you could externalize the client rules into a separate javascript file so that you don’t have to repeat it everywhere.