ASP.NET MVC4 regex model authentication attribute does not work on client side with accented characters

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.

+8
jquery-validate regex asp.net-mvc-4
source share
2 answers

It turns out someone asked the same question. My Google searches have not found it yet.

Data validation (regular expression) in asp.net mvc 4 - razor view

The issue was reported as a bug in the beta version of MVC 4.

+1
source share

Try the following:

 ^[a-zA-Z\u00E1]{2,50}$ 

Use \uXXXX , where XXXX hexadecimal character code.

0
source share

All Articles