我正在尝试验证一个属性,该属性必须具有九位代码并且不能以四个零或四个九结尾,并且必须在没有特殊字符的情况下输入。
我尝试了以下代码-
[RegularExpression(@"(^(?i:([a-z])(?!\1{2,}))*$)|(^[A-Ya-y1-8]*$)", ErrorMessage = "You can not have that")]
public string Test{ get; set; }
但它不起作用。
示例: exasdea0000
、asdea9999
、exasde@0000
或 as_ea9999
可以'无法输入。
我怎样才能做到这一点?
最佳答案
你可以这样写你的正则表达式:
^(?!\d+[09]{4}$)\d{9}$
解释:
^ // 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
关于c# - 模型中属性的正则表达式验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45833465/