假设您在ViewModel中有一个属性名称:
[Required(ErrorMessage = "{0} is required.")]
[RegularExpressionAttribute("[a-zA-Z äöåÄÖÅ]+", ErrorMessage = "Field {0} must contain only letters.")]
public string Name{ get; set; }
在某些浏览器中,这可以正常运行,因为它没有被编码:
<input class="name valid" data-val="true" data-val-regex="Field Name must contain only letters." data-val-regex-pattern="[a-zA-Z äöåÄÖÅ]+" data-val-required="Name is required." name="Name" type="text" value="">
但在某些浏览器中,这会被编码,因此正则表达式不起作用
<input class="name valid" data-val="true" data-val-regex="Field Name must contain only letters." data-val-regex-pattern="[a-zA-Z &#228;&#246;&#229;&#196;&#214;&#197;]+" data-val-required="Name is required." name="Name" type="text" value="">
我调查过并发现javascript存在问题 https://stackoverflow.com/a/4044768/1241400
有没有解决方法?
答案 0 :(得分:1)
你可以尝试Unicode转义:
"[A-Za-z \\u00E4\\u00F6\\u00E5\\u00C4\\u00D6\\u00C5]+"