Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex MVC正则表达式数据属性验证启动不正确_Regex_Asp.net Mvc - Fatal编程技术网

Regex MVC正则表达式数据属性验证启动不正确

Regex MVC正则表达式数据属性验证启动不正确,regex,asp.net-mvc,Regex,Asp.net Mvc,无论在字段中输入什么,以下正则表达式属性都会触发错误。这是在客户端发生的。此外,它显示的是通用消息,而不是指定的消息。你能帮忙吗 公共类注册器模型 { [Required] [StringLength(63, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)] [RegularExpression(@"/^[a-z\d]+([-_][a-z\d]+)*

无论在字段中输入什么,以下正则表达式属性都会触发错误。这是在客户端发生的。此外,它显示的是通用消息,而不是指定的消息。你能帮忙吗

公共类注册器模型

{

    [Required]

    [StringLength(63, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]

    [RegularExpression(@"/^[a-z\d]+([-_][a-z\d]+)*$/i",ErrorMessage="The Site Name can only contain letters from a-z (no accents), numbers from 0-9 and non consecutive hyphens or underscores.")]

    [Display(Name = "Site Name")]

    public string UserName { get; set; }

}
以下不同的正则表达式起作用,因此表达式本身或所需的@(字符串文字)字符肯定有问题,因为\d组合是C#转义字符


RegularExpression(“^[a-zA-Z][a-zA-Z0-9]+”,ErrorMessage=“站点名称只能包含a-Z字母(无重音)、0-9数字和非连续连字符或下划线。”)

以下内容似乎可以正常工作

[RegularExpression(@“^(a-z0-9{0,61}[a-z0-9]|[a-z0-9])$”,ErrorMessage=“站点名称只能包含来自a-z的字母(无重音)、来自0-9的数字以及非连续连字符或下划线。”)]