[英]Regular Expression validation of a property in a model
I am trying to validate a property which must have nine-digit code and cannot end with four zeros or four nines and must be entered without special characters. 我正在尝试验证必须具有九位数代码且不能以四个零或四个九结尾且必须输入的不带特殊字符的属性。
I tried the following code- 我尝试了以下代码-
[RegularExpression(@"(^(?i:([a-z])(?!\1{2,}))*$)|(^[A-Ya-y1-8]*$)", ErrorMessage = "You can not have that")]
public string Test{ get; set; }
But it's not working. 但这不起作用。
Example: exasdea0000
, asdea9999
, exasde@0000
or as_ea9999
can't be inputted. 例如:无法输入
exasdea0000
, asdea9999
, exasde@0000
或as_ea9999
。
How can I achieve this? 我该如何实现?
You can write your regex like this: 您可以这样编写正则表达式:
^(?!\d+[09]{4}$)\d{9}$
Explanation: 说明:
^ // 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.