Friday, 23 August 2013

DataAnnotaion Regular Expression always returns false for file input

DataAnnotaion Regular Expression always returns false for file input References I\'ve tried so many regular expressions for the RegularExpression DataAnnoation to check if the file extension is an image and it always returns false e.g. I\'ve also tried FileExtension attribute but it creates an error on the jquery.validation. Im using MVC 4 Razor [RegularExpression(@\"^.*\\.(jpg|gif|jpeg|png|bmp)$\", ErrorMessage = \"Please use an image with an extension of .jpg, .png, .gif, .bmp\")] public string MyImage { get; set; } and this is my markup
@Html.TextBoxFor(x => x.DepartmentImage, new { type = \"file\" }) @Html.ValidationMessage(\"DepartmentImageError\") @Html.ValidationMessageFor(model => model.DepartmentImage)
Could someone show me how to make it work

No comments:

Post a Comment