Ash*_*man 1 c# regex asp.net-mvc entity-framework data-annotations
我正在尝试验证必须具有九位数代码且不能以四个零或四个九结尾且必须输入的不带特殊字符的属性。
我尝试了以下代码-
[RegularExpression(@"(^(?i:([a-z])(?!\1{2,}))*$)|(^[A-Ya-y1-8]*$)", ErrorMessage = "You can not have that")]
public string Test{ get; set; }
Run Code Online (Sandbox Code Playgroud)
但这不起作用。
例如: exasdea0000,asdea9999,exasde@0000或as_ea9999不能被输入。
我该如何实现?
您可以这样编写正则表达式:
^(?!\d+[09]{4}$)\d{9}$
Run Code Online (Sandbox Code Playgroud)
说明:
^ // from start point
(?! // look forward to don't have
.+ // some characters
[09]{4} // followed by four chars of 0 or 9
$ // and finished
)
\d{9} // nine characters of digits only
$ // finished
Run Code Online (Sandbox Code Playgroud)