我在Entity Framework数据注释中使用以下正则表达式:
[RegularExpression("^(\\d|\\w)(\\d|\\w| |-){0}(\\d|\\w| |-)*$", ErrorMessageResourceName = "MyNameValidation", ErrorMessageResourceType = typeof(Resources.Resources))]
[Display(Name = "iFeedbackYouName", ResourceType = typeof(Resources.Resources))]
public string MyName { get; set; }
然而,它不允许我放置如下例子的文字:
Coçar
Colhões
Cabrão
Caíu
是否有可能允许它?
非常感谢
答案 0 :(得分:1)
您可以将非ascii字符显式添加到要允许它们出现的组中:
^(\d|\w)(\d|\w| |-){0}([çõ]|\d|\w| |-)*$
这也使用范围匹配两个样本字符串
^(\d|\w)(\d|\w| |-){0}([ç-õ]|\d|\w| |-)*$
你也可以使用unicode范围:
^(\d|\w)(\d|\w| |-){0}([\u00C0-\u02af]|\d|\w| |-)*$