我正在尝试验证一个属性,该属性必须具有九位代码并且不能以四个零或四个九结尾,并且必须在没有特殊字符的情况下输入。
我尝试了以下代码-
[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
