I have an MVC 4 model and I am creating html from it in the view using @ Html.TextBoxFor. In the model for one of the fields, I have the RegularExpression attribute, which is defined as follows:
[Required(ErrorMessageResourceType=typeof(ResourceFile), ErrorMessageResourceName="ResourceName1"
[RegularExpression(@"\w{3,5}", ErrorMessageResourceType=typeof(ResourceFile), ErrorMessageResourceName="ResourceName2")]
public string TestProperty { get; set; }
Note that the expression is more complex than that, but what I have here is suitable for testing. I set up unobtrusive client-side validation as described here: http://bradwilson.typepad.com/blog/2010/10/mvc3-unobtrusive-validation.html
The problem is that I need to accept Russian characters .. .Net regular expressions have different meanings for \ w regular expressions for javascript, and as such, server-side validation works as I expect, but not on the client side.
Is it possible to disable client-side validation for the RegularExpression attribute without disabling it for the Required attribute?
Otherwise, can you simply disable client-side validation for this single property without disabling all other properties of this model object?
source
share