In an ASP.NET MVC 3 project, I have a requirement to check a field name in a view to allow specific characters with a typing accent. Therefore, in my model model, I have a regular expression attribute defined in the corresponding property:
[RegularExpression("^[a-zA-Zรก]{2,50}$")]
Please note that this is not accurate code, understanding the problem is simplified.
This regular expression works on the server side, but does not work on the client side. If you look at the HTML address of the input field, it will contain this attribute:
data-val-regex-pattern="^[a-zA-Zá]{2,50}$"
As you can see, the accented character has been converted to an HTML object that breaks the regular expression. Can someone tell me why this is happening and how to fix it?
UPDATE
Sorry I'm a complete moron. I completely forgot that a couple of days ago we got to MVC 4 beta. Subsequently, I created two small test projects: one in MVC 3 and one in MVC 4. The problem exists only in MVC 4.
jquery-validate regex asp.net-mvc-4
Phil hale
source share