In an ASP.NET MVC 3 project I have a requirement to validate a name field in a view to allow a specific set accented characters. So in my view model I have an regular expression attribute defined on the appropriate property like this:
[RegularExpression("^[a-zA-Zá]{2,50}$")]
Please note this is not the exact code, it is simplified to make my problem easier to understand.
This regular expression works fine server side, but doesn't work client side. If you view the HTML of the input field is contains this attribute:
data-val-regex-pattern="^[a-zA-Zá]{2,50}$"
As you can see the accented character has been converted into a HTML entity which breaks the regular expression. Can anyone tell me why this is happening and how to fix it?
UPDATE
Apologies I am a complete moron. I had completely forgotten that we upgraded to MVC 4 beta a couple of days ago. Subsequently I've created a two small test projects, one in MVC 3 and one in MVC 4. The problem only exists in MVC 4.
Turns out someone has asked the same question. My Google searches didn't find it until now.
DataAnnotations validation (Regular Expression) in asp.net mvc 4 - razor view
The problem has been reported as a bug in MVC 4 beta.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With